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.

 채택된 답변

Star Strider
Star Strider 2016년 3월 6일

0 개 추천

See the im2bw function in the Image Processing Toolbox. Experiment until you get the result you want.

댓글 수: 2

anibb
anibb 2016년 3월 6일
Unfortunately i'm not able to use a built-in function such as im2bw
Without your image to work from, I can only guess at a solution. A grayscale image (that I assume you have) is a 2D matrix and has unit8 values from 0 to 255. You may have to ‘cut and try’, not uncommon with any signal processing problem.
Start with something like:
BinImg = GrayImg >127;
then display it with imshow to see the result. Then just vary the threshold up or down until you get the result you want.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Ahmet Cecen
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
Walter Roberson 2016년 3월 6일

0 개 추천

pixvals = sort(YourGreyImage(:));
middle_value = pixvals(round(end/2));
BWimage = YourGreyImage < middle_value;

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

태그

질문:

2016년 3월 6일

댓글:

2016년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by