Convertion from grayscale value to RGB vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Jan
am 13 Nov. 2017
Bearbeitet: Jan
am 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 Kommentare
Guillaume
am 13 Nov. 2017
Bearbeitet: Guillaume
am 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)
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!