How can i remove borders image?

8 ビュー (過去 30 日間)
Ehsan R
Ehsan R 2013 年 4 月 18 日
コメント済み: DGM 2024 年 3 月 5 日
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 件のコメント
Image Analyst
Image Analyst 2013 年 4 月 18 日
編集済み: Image Analyst 2013 年 4 月 18 日
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.

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2013 年 4 月 18 日
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 2024 年 3 月 5 日
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 件のコメント
DGM
DGM 2024 年 3 月 5 日
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

サインインしてコメントする。

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by