I am expanding the Bessi solution here a bit. I found it very useful to know how to make the image occupy the entire figure and be able to tightly control the size of the output image.
% prevent the figure window from appearing at all f = figure('visible','off'); % alternative way of hiding an existing figure set(f, 'visible','off'); % can use the GCF function instead % If you start getting odd error messages or blank images, % add in a DRAWNOW call. Sometimes it helps fix rendering % bugs, especially in long-running scripts on Linux. %drawnow; % optional: have the axes take up the whole figure subplot('position', [0 0 1 1]); % show the image and rectangle im = imread('peppers.png'); imshow(im, 'border','tight'); rectangle('Position', [100, 100, 10, 10]); % Save the image, controlling exactly the output % image size (in this case, making it equal to % the input's). [H,W,D] = size(im); dpi = 100; set(f, 'paperposition', [0 0 W/dpi H/dpi]); set(f, 'papersize', [W/dpi H/dpi]); print(f, sprintf('-r%d',dpi), '-dtiff', 'image2.tif');
If you want to display the shape in the matrix, enter "help @ avifile / addframe" and then extract the subfunction called "getFrameForFigure". This is a feature provided by Mathworks that uses some (currently) undocumented ways to extract data from a drawing.
Mr Fooz Jun 08 '09 at 12:57 2009-06-08 12:57
source share