How can i remove borders image?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi
i have a picture containing a figure(digit). i'd like to remove the borders of the picture from all four direction so that just the figure is left(no borders).
meanwhile please don'tuse imclearborder and imcrop.

1 commentaire
Image Analyst
le 18 Avr 2013
Modifié(e) : Image Analyst
le 18 Avr 2013
Why do you say that? Why "please don't use" the functions that can accomplish what you want to accomplish? It just doesn't make sense. Do you want to get the job done or not? Try posting your image to snag.gy or tinypic.com.
Réponses (2)
Image Analyst
le 18 Avr 2013
Your image did not come through for me - for some reason that site is banned by my company. Try the command imclearborder() in the Image Processing Toolbox. Or just use imcrop() or extraction
subimage = fullImage(row1:row2, column1:column2);
0 commentaires
Guilherme Freire Roberto
le 5 Mar 2024
Not the fanciest solution, but this worked for me:
%Remove borders from upper rows
checkRow = 0;
while(checkRow == 0)
if any(IMG(:,1))
checkRow = 1;
else
IMG = IMG(:,2:end);
end
end
%Remove borders from bottom rows
checkRow = 0;
while(checkRow == 0)
if any(IMG(:,size(IMG,2)))
checkRow = 1;
else
IMG = IMG(:,1:end-1);
end
end
%Remove borders from left columns
checkColumn = 0;
while(checkColumn == 0)
if any(IMG(1,:))
checkColumn = 1;
else
IMG = IMG(2:end,:);
end
end
%Remove borders from right columns
checkColumn = 0;
while(checkColumn == 0)
if any(IMG(size(IMG,1),:))
checkColumn = 1;
else
IMG = IMG(1:end-1,:);
end
end
1 commentaire
DGM
le 5 Mar 2024
It works, but if you're already familiar with any(), you can simplify a lot.
% find ROI geometry
inpict = any(inpict,3); % collapse channels
mkr = any(inpict,2); % find rows with nonzero elements
mkc = any(inpict,1); % find cols with nonzero elements
r1 = find(mkr,1,'first');
r2 = find(mkr,1,'last');
c1 = find(mkc,1,'first');
c2 = find(mkc,1,'last');
% crop original image to extents
inpict = inpict(r1:r2,c1:c2,:); % all channels
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!