-
Notifications
You must be signed in to change notification settings - Fork 21
RMODE
RMode gives us the effects like that of the famous magic color mode in various document scanning mobile apps.
RMode works by performing black point selection on the input image followed by white point selection on it.
Following code snipet from scan package of Java will give better understanding about RMode's operation,
case RMODE:
processedImg = inputImg.clone();
this.blackPointSelect();
this.whitePointSelect();
break;
First of the three lines in RMODE simply copies the input image into another Mat object denoted by processedImg which is a global instance variable also used by the methods implementing RMode. As of now, we can ignore it as it has nothing to do with understanding RMode's a;gorithm, it is simply there for the sake of implementation.
Next line calls blackPointSelect
method. This method performs black point selection on the image pointed by processedImg.
The third and the last line before break;
calls the whitePointSelect
method which now performs white point selection on processedImg.
Hence, the RMode is performed successfully and we have the ouput image (processedImg
) that looks like a scanned document ! 😁😁
NOTE
Methods
blackPointSelect
&whitePointSelect
require some integer values for black Point and white Point in order to implement the processing. As per my Java code; inside the main method we have to first create an objectscanner
of the Scan class. blackPoint & whitePoint values are provided as arguments to the constructor ofscanner
and to implement the desired mode of processing on input image we simply have to call the method scanImage. (refer code shown below)
In Python code, blackPoint & whitePoint values are defined in the main funtion before calling the functions whitePointSelect & blackPointSelect (refer source code)
Following code snipet from my project's main
method will make it clear,
/* read the input image and store it as Mat object */
Mat image = Imgcodecs.imread("C:/Users/Sourabh Khemka/Desktop/RScan/ML/dataset/data_img_271.jpg");
/* Create an object of Scan class. Also provide image, kernel size, blackPoint & whitePoint as input to the constructor */
Scan scanner = new Scan(image, 14, 50, 160);
/* call the scanImage method. Provide the desired mode of operation as argument to the method */
Mat scannedImg = scanner.scanImage(Scan.ScanMode.RMODE);
kernelSize
(see above code snipet) is discussed in High Pass Filter.
Input image :
Output image :
email id : [email protected]