Creating a bounding box that is not a perfect rectangle
이전 댓글 표시
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
Matt J
2023년 1월 14일
Images have to be rectangular.
ISABELLE GUNDRUM
2023년 1월 14일
Matt J
2023년 1월 14일
Yes, certainly. Exactly how though depends on the analysis to be done.
Walter Roberson
2023년 1월 14일
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.
채택된 답변
추가 답변 (1개)
Image Analyst
2023년 1월 14일
0 개 추천
See attached manual-drawing ROI definition examples.
카테고리
도움말 센터 및 File Exchange에서 ROI-Based Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
