# Revision history [back]

basarkir, can you please rephrase your question? It is hard to understand.

Anyway, when you are taking ROI of the image (as you did in your example), no copy is preformed. There still single image buffer for both img1 and roiImg. They are just pointing to different parts of it. So when you change content of roiImg, content of img1 is changed as well.

1) If you are working with gray images, it makes sense to convert them all prior to making any operations on them (clone and such).

2) If you are working with gray images than read them as gray images when you are using imread. Its default is to read image as 3-channel image, but you may force it to read it as 1-channel image, or you may read the image as is.

Mat color      =imread("imageLight100.bmp",1); // read the image as 3-channel image


3) imread() returns image in BGR format not RGB, so proper flag for cvtColor will be CV_BR2GRAY.

4) I don't see why you copied img2 to roiImg. This will just erase all content of roiImage and replace it with content of img2 (including width and height).

To put this all together, if you want to make histogram equalization to part of the image it should be writen this way:

Mat img = imread("imageLight100.bmp",0);  // read the image as gray image
Mat roiImg = img(Rect(100,100,200,200));  // take ROI from image
equalizeHist(roiImg,roiImg);              // perform equalization of ROI
imshow("roiImage",roiImg);                // show only equalized ROI
imshow("image",img);                      // show whole image while part of it was equalized
waitKey();


basarkir, can you please rephrase your question? It is hard to understand.

Anyway, when you are taking ROI of the image (as you did in your example), no copy is preformed. There still single image buffer for both img1 and roiImg. They are just pointing to different parts of it. So when you change content of roiImg, content of img1 is changed as well.

1) If you are working with gray images, it makes sense to convert them all prior to making any operations on them (clone and such).

2) If you are working with gray images than read them as gray images when you are using imread. Its default is to read image as 3-channel image, but you may force it to read it as 1-channel image, or you may read the image as is.

Mat color      =imread("imageLight100.bmp",1); // read the image as 3-channel image


3) imread() returns image in BGR format not RGB, so proper flag for cvtColor will be CV_BR2GRAY.CV_BGR2GRAY.

4) I don't see why you copied img2 to roiImg. This will just erase all content of roiImage and replace it with content of img2 (including width and height).

To put this all together, if you want to make histogram equalization to part of the image it should be writen this way:

Mat img = imread("imageLight100.bmp",0);  // read the image as gray image
Mat roiImg = img(Rect(100,100,200,200));  // take ROI from image
equalizeHist(roiImg,roiImg);              // perform equalization of ROI
imshow("roiImage",roiImg);                // show only equalized ROI
imshow("image",img);                      // show whole image while part of it was equalized
waitKey();