# Binarize a byte-formatted image

I have an image that I've imported as type "Byte" (I need to work with pixel values in this format). Let's just say the image is

foo = Image[RandomInteger[{0,255}, {8, 12}], "Byte"]


If I look at the image data with

ImageData[foo]


the data is returned as "Bit". I can convert this by specifying I want the data in a different format with

ImageData[foo, "Byte"]


What I need to do now though is to Binarize the image using data in "Byte" format. How do I do this? If I run

Binarize[foo, 50]


it returns all 0's. I'm assuming I have to convert "50" into it's Bit form right?

-
I might be wrong, but I believe you always need to assume a range 0..1 in most image functions, regardless of the underlying storage format. So it would be Binarize[img, 50/255], not Binarize[img, 50]. –  Szabolcs Feb 25 '13 at 17:43
Also, I'm not sure what you mean by 'the data is returned as "Bit"'. ImageData just returns a matrix of real numbers. You might want ImageData[foo, ImageType[foo]] to get it in the same format as it's stored. –  Szabolcs Feb 25 '13 at 17:47
perhaps you should explain what are you trying to do with the data ... Binarize[] will work the same irrespective to your data representation –  belisarius Feb 25 '13 at 18:22
I'm working with some satellite imagery and want to create a mask of all pixels whose values is greater than a specified threshold (50 for example -- the data are typically represented on a scale from 0-255). I can convert the threshold (50/255) but I'm not sure if it will do what I think it does. Will the translation mean that 50 out of 255 is the same as 50/255 out of 1? –  ShaunLangley Feb 25 '13 at 19:12
Mathematica rescales the values in the image to go from 0 to 1 (instead of 0 to 255, or however it was stored in the original data file). So Szabolcs has given you the right answer: Binarize[img,50/255] –  bill s Feb 25 '13 at 19:30