Home Scaling Mat elements to [0..255] range with OpenCV on Android
 I am trying to convert some OpenCV python code to Java and I ran into a problem of finding the correct functions in Java wrapper. The python code in question is calculating the Scharr gradient along the x-axis as: # compute the Scharr gradient of the blackhat image and scale the # result into the range [0, 255] gradX = cv2.Sobel(blackhat, ddepth=cv2.CV_32F, dx=1, dy=0, ksize=-1) gradX = np.absolute(gradX) (minVal, maxVal) = (np.min(gradX), np.max(gradX)) gradX = (255 * ((gradX - minVal) / (maxVal - minVal))).astype("uint8")  [Code is from pyimagesearch website - Detecting machine-readable zones in passport images - blog post] What I have in Java is: Imgproc.Sobel(blackhat, gradX, CvType.CV_32F, 1, 0, -1, 1.0, 0, Core.BORDER_DEFAULT); Core.convertScaleAbs(gradX, gradX); Core.MinMaxLocResult minmax = Core.minMaxLoc(gradX);  This should output the same result as the first three lines of the python code. But I got stuck on the last one. How does one perform the scaling of the gradX back into the [0..255] range with Java API? Also does the convertScaleAbs function perform the same action as NumPys absolute?