Creating a bounding box that is not a perfect rectangle
Show older comments
Currently, my code allows me to select a ROI in an image and then it creates a bounding box. This bounding box, however, is a rectangle while I would like the cropped image to remain as the ROI shape and not a perfect rectangle.
clear varaiables, close all
if ~exist("image_analysis.mlx")
% 1. Load the file and scale it
before = "blue_close"; white = "white_close"; after = "group1_close";
A = imresize(imread(before,'jpg'),1.00);
B = imresize(imread(white,'jpg'),1.00);
C = imresize(imread(after,'jpg'),1.00);
% % 2. manually specify the ROI using the original image
imshow(A)
h = drawpolygon('FaceAlpha',0);
h.Color = 'yellow';
% find a bounding box of ROI to further cut the image smaller
% bbox = [xmin ymin xmax ymax]
hmin = min(h.Position); hmax = max(h.Position);
bbox = [hmin hmax-hmin];
% 3. Crop ROI for both image a and image b using the bounding box
Cb = imcrop(B,bbox);
Ca = imcrop(A,bbox);
Cc = imcrop(C,bbox);
clear A B C
save sqa.mat
else
load sqa.mat
end
Thanks!
4 Comments
Matt J
on 14 Jan 2023
Images have to be rectangular.
ISABELLE GUNDRUM
on 14 Jan 2023
Matt J
on 14 Jan 2023
Yes, certainly. Exactly how though depends on the analysis to be done.
Walter Roberson
on 14 Jan 2023
For example if you were to create a mask from the ROI, and you were to double() that so that the values become numeric 0 and numeric 1 instead of logical 0 (false) and logical 1 (true), then you could pass that numeric array to regionprops as the "label" array, and pass in a grayscale image as the next parameter. You can then ask about the properties and it will only calculate the properties for the marked locations.
That said... if you were calculating a property such as Solidity which has to do with the area occupied relative the area of the bounding box, then the bounding box is still going to be calculated as a rectangle.
Accepted Answer
More Answers (1)
Image Analyst
on 14 Jan 2023
0 votes
See attached manual-drawing ROI definition examples.
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!