Convertion from grayscale value to RGB vector
2 次查看(过去 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
0 个评论
回答(1 个)
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
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)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!