Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

There also few remarks about your code:

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
Mat gray       =imread("imageLight100.bmp",0); // read the image as 1-channel image
Mat grayOrColor=imread("imageLight100.bmp",-1); // read the image as is

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.

There also few remarks about your code:

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
Mat gray       =imread("imageLight100.bmp",0); // read the image as 1-channel image
Mat grayOrColor=imread("imageLight100.bmp",-1); // read the image as is

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();