How to crop a region of interest in an image based on the area in pixels?
7 vues (au cours des 30 derniers jours)
In the code below, I open and crop three images by selecting the four corners of the region of interest, which is a rectangular shape, but because it isn't perfect, a polygon is drawn.
clear varaiables, close all
if ~exist("subject_image_analysis.mlx") % for development, if ROI already set, do not repeat
% 1. Load the file and scale it 4:1 at each side
before = "PIC_1596"; white = "PIC_1539"; after = "PIC_1601";
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
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]; % 1x4 vector: upper left row and column indices, # rows, # cols of ROI
% 3. Crop ROI for both image a and image b using the bounding box
Cb = imcrop(B,bbox); % ROI for image a
Ca = imcrop(A,bbox); % ROI for image b
Cc = imcrop(C,bbox);
% clear original images
clear A B C
save sqa.mat % save these two ROIs andrelated parameters in a .mat file
After this, I would like each image to be cropped further into 8 same sized rectangles (or regions). How can this be achieved using the area in pixels?
Ideally, this would look like 4 regions in the top half and 4 regions in the bottom half, so that each region can be further analyzed individually.