MATLAB Answers

0

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

Asked by Preetham Manjunatha on 6 Aug 2017
Latest activity Commented on by Preetham Manjunatha on 6 Aug 2017
Accepted Answer by Jan
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.

  0 Comments

Sign in to comment.

1 Answer

Answer by Jan
on 6 Aug 2017
 Accepted Answer

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

  1 Comment

Jan:
Thanks! It worked.
RGB = insertShape(rgb,'Rectangle',allBBoxCoords,'LineWidth',5,... 'Color','green');

Sign in to comment.