MATLAB Answers

RGB Image re-interlacing missing output colors.

5 ビュー (過去 30 日間)
Alex Valente
Alex Valente 2020 年 7 月 29 日
コメント済み: jonas 2020 年 7 月 29 日
I want to start by stating I am a pretty advanced coder, but I am fairly new to the Matlab world and am still grasping the more fundamental pieces of image proccesing.
I have an imput image that I sperate into two "interlaced frames". This is easy, I use the following code to seperate the image row by row.
function [A, B] = deinterlace(inImage)
A = inImage(1:2:end,:,:);
B = inImage(2:2:end,:,:);
end
I realize this might not be the "best" method of doing this, but for my experiments this will sufice. That being said, if there is a more "Matlab/correct" way of doing this it would be much apricaited, mainly because I want to learn the proper way of doing things (outside of the tutorials, nothing is as good as an experinced coder).
My issue is when I try to re-interlace the image. Since the image is RGB, it is stored in a (W x H x 3) matrix and when I try to stich the image back together I seem to be loosing some formating of the data. As such some of the color is leftout of the output image (see image bellow).
The code below is what I have tried...commented out section produces the exact same result, but is "not the Matlab" solution, or so I'm told. Any advice on what I am doing wrong would be much apriciated.
function [outImage] = interlace(A, B)
w = size(A);
outImage = zeros(w(1)*2, w(2), w(3));
outImage(1:2:end,:,:) = A;
outImage(2:2:end,:,:) = B;
% outImage = zeros(w(1)*2, w(2), w(3));
% for i = 1:2:w*2
% index = ceil(i/2);
% outImage(i,:,:) = A(index,:,:);
% outImage(i+1,:,:) = B(index,:,:);
% end
end
(Top: Input Image, Middle: Two halfs of interlaced image, Bottom: Result of re-interlacing)

  0 件のコメント

サインインしてコメントする。

採用された回答

jonas
jonas 2020 年 7 月 29 日
編集済み: jonas 2020 年 7 月 29 日
I'm guessing your input image is uint8 (0 = black, 255 = saturated) and that your output image is class double (0 = black, 1 = saturated).
Try changing this line
outImage = zeros(w(1)*2, w(2), w(3),'uint8');

  2 件のコメント

Alex Valente
Alex Valente 2020 年 7 月 29 日
That was exactly it! Thank you so much. I was unaware that it normalized the scale for double values.
jonas
jonas 2020 年 7 月 29 日
my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by