How can I change an array from grayscale to binary?
이전 댓글 표시
I have a 2D array representing a grayscale image. This array is stored as doubles. When I try to use the function im2bw on the array stored as a double, I get a completely white image regardless of the threshold value. The documentation says the function accepts doubles as input. When I typecast the array to uint8 by calling converted_array = uint8(array), the im2bw function works properly.
Problem is that I'm using LabVIEW to create the 2D array and even if I typecast it in LabVIEW, MATLAB still sees the array as doubles.
Am I missing something when I'm using the im2bw function? How can I get it to work with doubles?
Edit: Some sample data from the doubles array
4294967295.00000 4278124286.00000 4210752250.00000 4278124286.00000 4210752250.00000 4294967295.00000 4244438268.00000 4193909241.00000 4261281277.00000 4294967295.00000 4278124286.00000 4294967295.00000 4193909241.00000 4294967295.00000 4294967295.00000 4278124286.00000
What the data looks like after LabVIEW converts it to U8:
255 254 250 254 250 255 251 249 253 255 255 255 249 255 255 255
댓글 수: 1
Ashmil Mohammed
2015년 7월 10일
Please copy-paste a little part of the array
채택된 답변
추가 답변 (2개)
Image Analyst
2015년 7월 10일
I never use it. I simply threshold using some value that I have determined.
binaryImage = grayImage > someThreshold;
You might like to use my visual/interactive app for thresholding an image. See my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 for that plus several other nice apps.
Ashmil Mohammed
2015년 7월 10일
0 개 추천
Possible solution: *Divide whole array by 255
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!