Convertion from grayscale value to RGB vector

1 view (last 30 days)
Hello, I am trying to figure out how I have to convert a grayscale value which has been exracted from a grayscale frame of an avi video to the right RGB value (vector). I am using the code below:
if true
% Extract frames from video and save it on an Array
folder = fileparts(which('diffusion_process.avi'));
movieFullFileName= fullfile(folder,'diffusion_process.avi');
videoObject = VideoReader(movieFullFileName);
numberOfFrames = videoObject.NumberOfFrames;
for frame = 1:numberOfFrames
thisFrame = read(videoObject,frame);
if frame == 1
h = size(thisFrame,1);
w = size(thisFrame,2);
processo = zeros(h, w, 3, numberOfFrames);
end
processo(:, :, :, frame) = thisFrame;
end
i = 1;
Color=[processo(X,Y,1,i),processo(X,Y,1,i),processo(X,Y,1,i)];
end
The vector called Color always returns white. I am not sure if I have set the RGB vector in the correct way. Any suggestions? Many thanks Davide

Answers (1)

Jan
Jan on 13 Nov 2017
Edited: Jan on 13 Nov 2017
Your processo array is a double array with the range [0, 1], but the frames obtained from the movie might have the type INT8 with a range of 0:255. Then all but a 0 value produces a white color in the double array. Convert the types:
processo(:, :, :, frame) = im2double(thisFrame);
or:
processo(:, :, :, frame) = double(thisFrame) / 255;
  2 Comments
Guillaume
Guillaume on 13 Nov 2017
Edited: Guillaume on 13 Nov 2017
Alternatively, create processo so that it is the same class as the frame:
%in the if block
processo = zeros(h, w, 3, numberOfFrames, 'like', thisFrame);
This will use less memory than converting the whole lot to double (8 times the memory of an uint8 array)
Davide Magnelli
Davide Magnelli on 13 Nov 2017
Now Color = [0.8118 0.8118 0.8118] (18th frame for example) and is a light gray but I'd wish to obtain a RGB color. Is it possible?

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!