How can i remove borders image?

5 Ansichten (letzte 30 Tage)
Ehsan R
Ehsan R am 18 Apr. 2013
Kommentiert: DGM am 5 Mär. 2024
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 Kommentar
Image Analyst
Image Analyst am 18 Apr. 2013
Bearbeitet: Image Analyst am 18 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 18 Apr. 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);

Guilherme Freire Roberto
Guilherme Freire Roberto am 5 Mär. 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 Kommentar
DGM
DGM am 5 Mär. 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

Melden Sie sich an, um zu kommentieren.

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by