Automatically crop an image

2 vues (au cours des 30 derniers jours)
Eliska Paulikova
Eliska Paulikova le 24 Oct 2022
Hello, I need to automatically crop the rectangular part, how can I do it?
Thank you
Thank you

Réponse acceptée

DGM
DGM le 24 Oct 2022
Modifié(e) : DGM le 24 Oct 2022
Depending on the requirements and what the other photos look like, this might be one way, or at least a start
% this is an rgb image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1167208/image.jpeg');
% make a mask that roughly selects the object
mk = rgb2gray(inpict)<200; % basic thresholding
mk = imopen(mk,strel('disk',20)); % use small features to break up background
mk = imclearborder(mk); % get rid of any framing
mk = bwareafilt(mk,1); % select only the largest remaining blob
imshow(mk)
% crop area by direct indexing
rows = any(mk,2);
cols = any(mk,1);
outpict = inpict(rows,cols,:); % this is also RGB
imshow(outpict);
  1 commentaire
Eliska Paulikova
Eliska Paulikova le 24 Oct 2022
Thank you so much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by