How do I change an image to binary?
古いコメントを表示
I have a picture of a black wrench with a gray background. I need to figure out a threshold value that separates the two so that I can set the background pixels to 0 and the pixels of the wrench to 1. I just need help figuring out the threshold value and extract the background pixels vs. the wrench pixels. I think I can figure out how to then change them to either 1 or 0.
採用された回答
その他の回答 (2 件)
Ahmet Cecen
2016 年 3 月 6 日
編集済み: Ahmet Cecen
2016 年 3 月 6 日
0 投票
ImageSegmenter should help you if you have the toolbox, since you sound like a novice user. http://www.mathworks.com/help/images/image-segmentation-using-the-image-segmenter-app.html
Otherwise use the histogram function. If you are lucky, it will be shaped like the back of a camel and you can find a valley between to peaks, then use that value as your threshold. http://www.mathworks.com/help/matlab/ref/histogram.html
There is also a function that finds an automatic threshold for you if you trust it, but it also requires the toolbox: http://www.mathworks.com/help/images/ref/graythresh.html
Walter Roberson
2016 年 3 月 6 日
pixvals = sort(YourGreyImage(:));
middle_value = pixvals(round(end/2));
BWimage = YourGreyImage < middle_value;
カテゴリ
ヘルプ センター および File Exchange で Images についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!