Skip to content

Black Point Select

MSD_11 edited this page Jan 4, 2021 · 8 revisions

As discussed in introduction, Black point selection in Python requires some type conversion and thresholding operations apart from the map function. In Java, we don't need to do any such add-on operations and simply implement the mapping using Core methods.

To map variable x which's in the range [in_min, in_max] to the range [out_min, out_max] we need to perform following maths,

x = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

Hence, we can perform the black point selection in Python using follwing line of code,

image = (image - blackPoint) * (255)/(255 - blackPoint)

Mapping image pixel values in Java using above pseudo code:

Java implementation of map method will be done in steps. First we subtract blackPoint Scalar value from the image using,

Core.subtract(processedImg, new Scalar(blackPoint, blackPoint, blackPoint), processedImg);

In above step, blackPoint value is subtracted from each pixel of all the three RGB channels of processedImg and the resultant image is stored in the destination same as src i-e processedImg

ProcessedImg now needs to be multiplied by (255)/(255 - blackPoint). This operation is acheived as follows,

float tmp = (255.0f) / (255.0f - blackPoint);
Core.multiply(processedImg, new Scalar(tmp, tmp, tmp), processedImg);

We store the value to be multiplied in a float variable and use Core.multiply method to execute the multiplication & hence complete the black point selection operation successfully !

Clone this wiki locally