Effacer les filtres
Effacer les filtres

How to crop a region of interest in an image based on the area in pixels?

3 vues (au cours des 30 derniers jours)
ISABELLE GUNDRUM
ISABELLE GUNDRUM le 14 Déc 2022
Modifié(e) : Image Analyst le 14 Déc 2022
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
imshow(C)
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
else
load sqa.mat
end
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.
  1 commentaire
Image Analyst
Image Analyst le 14 Déc 2022
Do you want to crop out and save the 1/8th image in 8 variables? Or a single cell array with 8 cells where each cell is one of the subimages? What are you going to do with these? Maybe you can just loop 8 times, extracting one subimage during each iteration and use it right away to compute something.
See the FAQ:

Connectez-vous pour commenter.

Réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by