Skip to content Skip to sidebar Skip to footer

Compare Histograms Of Specific Areas Of Two Images? Opencv

Basically, I want to be able to compare two histograms, but not of whole images just specific areas. I have image A and have a specific rectangular region on it that I want to comp

Solution 1:

Note: The following is in C++ but I think it is not hard to find the equivalent functions for python.

You can find the histogram of an image using this tutorial. So for example for the lena image we get:

lenahist

In your case, since you have the rectangle coordinates, you can just extract the ROI of the image:

// C++ code
cv::Mat image = cv::imread("lena.png", 0);
cv::Rect roiRect = cv::Rect(150, 150, 250, 250);
cv::Mat imageRoi = image(roiRect);

and then find the histogram of just the ROI with the same way as above:

lenaroihist

Is this what you wanted (in theory at least) or I misunderstood?

Post a Comment for "Compare Histograms Of Specific Areas Of Two Images? Opencv"