i suppose you have a code like this:
using Images, TestImages
img = TestImage("mandrill")
img2 = Gray.(img) #grayscale image from color image
the format of the images are a type of Normalized integer, between 0 and 1, so to convert to values between 0 and 255, we just have to multiply:
img3 = 255 .* img2
img4 = convert.(Float64,img3) # to transform the array of colors to array of Float64
Knowing about the implicit types used in the images.jl package, you can actually extract directly the integer value, without converting to a floating number:
img3 = broadcast(x->Int(x.val.i),img2) #applies the function over the entire image
this works because:
- Gray is a struct with val as a field of type Normed number
- a Normed Number is a struct with i as the integer value, and because is a N0f8 type, is normalized with 8 bits, so the max value of that integer is 255 (what you are looking for, using the Mandrill example from TestImages)
So, the fist solution is general, the second solution is more specific and fast, you choose .
Also, remember to always put a minimal working example, the people can’t help you if they don’t understand what your code is like, i think what you have based on former questions you asked here.
PD: i don’t work with images in julia, but is fun!