Ask Your Question
1

How to perform changes in both sub-image and original image ?

asked 2013-05-27 12:33:59 -0600

Jawaher Khemakhem gravatar image

updated 2015-10-04 07:52:25 -0600

I have limited a region of interest in a binary image with a rectangle . I have convert this rectangle to a new matrix . now whenever I perform an operation in this matrix there is no change in the original image , but what I want is to have a change in the original image .

     // region of interest 
       Rect roi(maxloc.x,maxloc.y, m2.cols,m2.rows);
    //new matrix  
       Mat image_roi = m1(roi);
    //perform operations 
       bitwise_not(image_roi,image_roi);
      image_roi=choice(image_roi);
     imshow("image",m1);//there is no change in m1
edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
2

answered 2013-05-27 13:04:51 -0600

yes123 gravatar image

Try

Mat image_roi(m1,roi);

But your solution should already work too

edit flag offensive delete link more
2

answered 2013-05-27 13:19:54 -0600

rics gravatar image

Although your example is not complete I think the problem is that you use m1 instead of m2 in the line

Mat image_roi = m1(roi);

OpenCv does not reallocate matrices for efficiency reasons, only when it has to. As m1 is not initialized in your code snippet it needs to be allocated independently of m2. If you use the following code

Mat image_roi = m2(roi);

then image_roi would use the same memory area as m2 but with a different matrix header so modifications of the roi would alter the original image.

See the Mat tutorial for details.

edit flag offensive delete link more
0

answered 2014-10-05 18:01:05 -0600

Sebita gravatar image

Thanks, it worked for me

Mat m1=image;
Rect roi(r.x,r.y, r.width,r.height);
Mat image_roi(m1,roi);
imshow("image",image_roi);
edit flag offensive delete link more
-1

answered 2014-10-06 01:28:12 -0600

govardhana padavala gravatar image

Hi jawahar, your intesion was clear but problem in you code. That is you need to declare the matrix(mat) object coordinates then your will get expected output, here you missed out the mat object coordinates

Thank you, its gov...

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-27 12:33:59 -0600

Seen: 2,653 times

Last updated: Oct 06 '14