How can I change an array from grayscale to binary?
Mostra commenti meno recenti
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 Commento
Ashmil Mohammed
il 10 Lug 2015
Please copy-paste a little part of the array
Risposta accettata
Più risposte (2)
Image Analyst
il 10 Lug 2015
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
il 10 Lug 2015
0 voti
Possible solution: *Divide whole array by 255
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!