how to remove black margines automatically from images?

19 ビュー (過去 30 日間)
sara
sara 2015 年 1 月 30 日
コメント済み: khalil yossefi 2020 年 1 月 7 日
how can i automatically remove black margines around border of an image,like the dark lines remains around an image when you scan it,there is also this link which describes about this,but can any one gives a better code,thanx http://uk.mathworks.com/matlabcentral/answers/128133-automatically-trim-remove-crop-black-borders-margins-from-images-volumes i also used imclearborder,but it wont work on my image,
  4 件のコメント
Image Analyst
Image Analyst 2015 年 1 月 30 日
Just use imcrop() or regular indexing to extract a subimage.
sara
sara 2015 年 1 月 30 日
編集済み: sara 2015 年 1 月 30 日
there are more than one image,and the problem is that in one image the margin is on the right side,in another it is in left side,and even their size is different,in one image it is a thick line,another is a thin line, i will work on regular indexing to extract sub image,thank you

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

採用された回答

Image Analyst
Image Analyst 2015 年 1 月 30 日
I'm not sure why that is a problem. Just find the first and last column and crop like I suggested:
horizontalProfile = mean(grayImage, 1) > 10; % Or whatever.
firstColumn = find(horizontalProfile, 1, 'first');
lastColumn = = find(horizontalProfile, 1, 'last');
subImage = grayImage(:, firstColumn, lastColumn);
Is there a problem with that? I think it should handle the cases you mentioned. Does it not?
  5 件のコメント
Image Analyst
Image Analyst 2020 年 1 月 4 日
Oh, sorry - I didn't read closely enough, or I misinterpreted.
To get the bounding box of everything, here is one way
[r, c] = find(binaryImage);
row1 = min(r);
row2 = max(r);
col1 = min(c);
col2 = max(c);
croppedImage = grayImage(row1:row2, col1:col2);
khalil yossefi
khalil yossefi 2020 年 1 月 7 日

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLanguage Support についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by