Convert uint8 image to doubles

3 Ansichten (letzte 30 Tage)
Jacob
Jacob am 23 Aug. 2013
Hello,
I'm trying to convert a png image from the web to a single 2d array of doubles, scaled from 0 to 1.
im2double works. But the problem is the image is actually 3 2d arrays. The first corresponds to red intensities, second one to green intensities, and third one is blue intensities (this seems to be a common format). im2double converts each of the three 2d arrays, but I need to combine them into a single 2d array for black/white intensity.
Is there a function for this? Any help?

Antworten (1)

Walter Roberson
Walter Roberson am 23 Aug. 2013
im2double() applied to the 3D ("truecolor") array would convert the entire array.
If the original image is grayscale that has been represented as RGB, then the three color planes would be equal to each other. You would not need to convert each of the planes individually to get out a grayscale image represented in RGB
repmat( im2double(PNGImage(:,:,1)), 1, 1, 3); %convert one plane, clone that
If for some reason you do have three separate arrays, say R, G, B, then
cat(3, im2double(R), im2double(G), im2double(B))
or equivalently
im2double( cat(3, R, G, B))
  1 Kommentar
Jacob
Jacob am 23 Aug. 2013
Thanks for the tips!
I found what I was looking for - to convert a 3D RGB array, matlab has rgb2double() which takes an RGB array with values from 0 - 255 and returns a single 2D array with double values from 0 - 1.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by