How to use threshold in this problem?

I convert this picture into bw using c=im2bw(b,graythresh(b)); but the problem is the straight line is disconnected as picture below. It supposed to be straight single line. What kind of segmentation technique that I need to use?

 採用された回答

Alessandro Masullo
Alessandro Masullo 2015 年 1 月 23 日

0 投票

Supposed your image varies from o to 1, you could use a threshold in this way:
THR = 0.5
above = image>=THR;
image(above) = 1;
image(~above) = 0;

6 件のコメント

muhammad ismail
muhammad ismail 2015 年 1 月 23 日
編集済み: muhammad ismail 2015 年 1 月 23 日
So how to apply in this coding?
a=imread('S2a.jpg');
b= imcrop(a,[83 48 550 353]);
c=im2bw(b,graythresh(b));
Alessandro Masullo
Alessandro Masullo 2015 年 1 月 23 日
a=imread('S2a.jpg');
b= imcrop(a,[83 48 550 353]);
c = im2double(b);
THR = 0.5
above = c>=THR;
c(above) = 1;
c(~above) = 0;
muhammad ismail
muhammad ismail 2015 年 1 月 23 日
But it display like picture below. a=imread('S2a.jpg');
b= imcrop(a,[83 48 550 353]);
c = im2double(b);
THR = 0.5;
above = c>=THR;
c(above) = 1;
c(~above) = 0;
imshow(c);
Alessandro Masullo
Alessandro Masullo 2015 年 1 月 23 日
That's because your line gray level is the same of the background, so you cannot use a simple conversion from gray to b/w, but you have to use an edge detection algorithm, as Image Analyst suggested:
muhammad ismail
muhammad ismail 2015 年 1 月 23 日
編集済み: muhammad ismail 2015 年 1 月 23 日
Ok now I understood. Thank you very much for your great explanation. By the way I have last question for you. How to display gray level like image above. Sorry I'm newbie in matlab.
Alessandro Masullo
Alessandro Masullo 2015 年 1 月 23 日
I just used imagesc(c). You can use different colormaps instead of the grey levels, use:
colormap jet
help colormap

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 1 月 23 日

0 投票

Like I said in your duplicate post, you can use imclearborder() and bwareaopen(), though there are better ways like background correction.

カテゴリ

ヘルプ センター および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by