Issue with getframe and getimage commands while saving the image (image size mismatch).

2 views (last 30 days)
Hello:
I have an issue while using getimage() command. I am trying to use a figure, first with imshow to initialize a color image (rgb from code) of size 1944x2592x3 pixels. After this, I want to overlay the bounding-boxes on the color image. I tried using getimage() to obtain the full-size image (1944x2592x3 pixels). It worked, but I am not getting the bounding-boxes overlaid image of full-size. Instead, I am getting a color image (rgb) of full-size.
If I use getframe(), I am getting the overlaid image but of smaller size. Anybody, please help me. I need the image(s) of the original size.
%% Matlab code used % Image overlay rgb = imoverlay(Igray, BW, [1 0 0]);
% Get bounding boxes coords st = regionprops(BW, 'BoundingBox' );
f = figure('Visible', 'off');
a = axes('Visible','off');
imshow(rgb);
hold on
for k = 1 : length(st)
thisBB = st(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)], EdgeColor','G','LineWidth',2 );
end
hold off
frame = getimage(f);
saving frame.cdata into a variable.

Accepted Answer

Jan
Jan on 6 Aug 2017
The problem is neither getframe not getimage, but rectangle: This function displays the rectangles on top of the image, but does not insert the pixel values into the image. If you take a screenshot afterwards by getframe, the rectangle are visible, but the resolution hast changed.
What you need is a tool to draw the rectangles into the RGB array directly. Then you do not need the indirection over the display in the figure. See https://www.mathworks.com/help/vision/ref/vision.shapeinserter-class.html and https://www.mathworks.com/help/vision/ref/insertshape.html

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!