0

I have displayed an image and plotted a rectangle over all the useless areas. Now i need to save this image in the form of a matrix, so that i can use it further.

figure,imshow(colz);
hold on;
for i=1:num
    if(i~=n)
        img=rectangle('Position',box(i,:),'FaceColor','k');
    end
end

This is a part of my whole code. I'm covering all the undesired parts with zeros. so now I'm left with my desired area and a background. How can i save the pixel values in another matrix so as to create a new image that contains this enhanced data?

Thanks

Amro
  • 123,847
  • 25
  • 243
  • 454
Tanuj
  • 1
  • 1
  • 1
    Duplicates: [Save a plot in Matlab as a matrix](http://stackoverflow.com/questions/3246185/save-a-plot-in-matlab-as-a-matrix), [Turn Matlab plot into image](http://stackoverflow.com/questions/1915891/turn-matlab-plot-into-image), [MATLAB how to plot x,y on image and save](http://stackoverflow.com/questions/3178336/matlab-how-to-plot-x-y-on-image-and-save), [How can I save an altered image in MATLAB?](http://stackoverflow.com/questions/575475/how-can-i-save-an-altered-image-in-matlab), etc. – gnovice Feb 03 '11 at 17:59
  • 3
    If you're simply trying to modify the image matrix `colz` by setting some pixels to black, then there's no reason to plot it. You can instead directly modify the data in the image matrix to create a new image. I discuss this in [my answer to this related question](http://stackoverflow.com/questions/575475/how-can-i-save-an-altered-image-in-matlab/575519#575519). – gnovice Feb 03 '11 at 18:08

1 Answers1

0

here try this

F = getframe(gcf);
% gcf is your figure currently displaying your image with the rectangle
%
y = F.cdata;
hold off
figure(2),imshow(y);
HashT
  • 209
  • 1
  • 4
  • 13