RGB Image re-interlacing missing output colors.

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

采纳的回答

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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by