I am trying to figure out how to draw rectangles on an image in Matlab.
Once the rectangles are drawn on the image I would like to save the changes.
Thanks in advance!
im=imread('face. jpg'); %Image read rectangle('Position', [10 10 30 30] ,... 'EdgeColor', 'r',... 'LineWidth', 3,... 'LineStyle','-');%rectangle properties imshow( im, rectangle); %draw rectangle on image. Save this answer.
[ xlim , ylim ] = boundingbox( polyin ) returns the x and y bounds of the smallest rectangle enclosing a polyshape . xlim and ylim are two-element row vectors whose first elements correspond to the lower x and y bounds, and whose second elements correspond to the upper x and y bounds.
roi = drawrectangle creates a Rectangle object and enables interactive drawing of the ROI on the current axes. To draw the ROI, position the pointer on the image. The cursor changes to a fleur shape. Click and drag to draw the rectangular ROI.
Use getframe
img = imread('cameraman.tif');
fh = figure;
imshow( img, 'border', 'tight' ); %//show your image
hold on;
rectangle('Position', [50 70 30 60] ); %// draw rectangle on image
frm = getframe( fh ); %// get the image+rectangle
imwrite( frm.cdata, 'savedFileName.png' ); %// save to file
See rectanlge
for more options on drawing rectangles. The 'Position'
argument for rectangle is in format [from_x from_y width height]
and is given in units of pixels.
Without using getframe:
im=imread('face.jpg'); %Image read
rectangle('Position', [10 10 30 30] ,...
'EdgeColor', 'r',...
'LineWidth', 3,...
'LineStyle','-');%rectangle properties
imshow( im, rectangle); %draw rectangle on image.
For more detail visit this MathWorks thread :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With