Image gray value adjustment (CC ++ source code)

xiaoxiao2021-03-06  56

The pixel value of the image, including brightness, contrast, and GAMMA correction algorithm, the environment is OpenCv4.0, VC6.0. The algorithm references the MATLAB function imadjust. /// perform histgram equalization for single channel image //

#include "cv.h" #include "highgui.h"

/ * Reference for correspondent MATLAB function: imadjustIMADJUST Adjust image intensity values ​​or colormap J = IMADJUST (I, [LOW_IN HIGH_IN], [LOW_OUT HIGH_OUT], GAMMA) maps the values ​​in intensity image I to new values ​​in J such that values ​​between. LOW_IN and HIGH_IN map to values ​​between LOW_OUT and HIGH_OUT values ​​below LOW_IN and above HIGH_IN are clipped;. that is, values ​​below LOW_IN map to LOW_OUT, and those above HIGH_IN map to HIGH_OUT You can use an empty matrix ([]) for [. LOW_IN HIGH_IN] or for [LOW_OUT HIGH_OUT] to specify the default of [0 1]. GAMMA specifies the shape of the curve describing the relationship between the values ​​in I and J. If GAMMA is less than 1, the mapping is weighted toward higher (brighter) Output Values. IF Gamma Is Greater Than 1, The Mapping IS Weighted Tower (DARKER) Output Values. If You Omit The Argument, Gamma Defaults To 1 (Linear Mapping).

Note That if high_out

IF (Low <0 &&ow> 1 && Bottom <0 && Bottom> 1 && Top <0 && TOP> 1) Return 1; // Intensity Transform for (Y = 0; Y height; y ) {for (x = 0; x width; x ) {VAL = ((Uchar *) (SRC-> ImageData src-> widthstep * y)) [x]; val = POW ((VAL - low2) / err_in, gamma * err_out bottom2; if (Val> 255) VAL = 255; if (Val <0) VAL = 0; // Make Src is in The Range [low, high ] ((Uchar *) (DST-> ImageData DST-> Widthstep * Y)) [X] = (UCHAR) VAL;}} Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-113847.html

New Post(0)