Convertion from grayscale value to RGB vector

1 次查看(过去 30 天)
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

回答(1 个)

Jan
Jan 2017-11-13
编辑:Jan 2017-11-13
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 个评论
Guillaume
Guillaume 2017-11-13
编辑:Guillaume 2017-11-13
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 2017-11-13
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by