Convertion from grayscale value to RGB vector

1 回表示 (過去 30 日間)
Davide Magnelli
Davide Magnelli 2017 年 11 月 13 日
コメント済み: Davide Magnelli 2017 年 11 月 13 日
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 Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by