MATLAB contains demosaic() function to convert Bayer pattern encoded image to true color, does it contain opposite function as well?

81 ビュー (過去 30 日間)
I am writing a VHDL entity that processes Bayer pattern image to generate a true color image. It would make things easier if MATLAB has a method to generate Bayer pattern encoded image from a given RGB image. I can then use it inside my testbench. How can this be achieved?

回答 (1 件)

Image Analyst
Image Analyst 2017 年 8 月 15 日
No - it would be in the "See also" section if there were. However, you can easily make one simply by interleaving your data in the required pattern.
% Read in sample image.
rgbImage = imread('peppers.png');
% Display the image.
subplot(2,1,1);
imshow(rgbImage);
title('Original RGB image', 'FontSize', 20);
% Create mosaiced image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
mosaicedImage = zeros(rows, columns, 'uint8');
for col = 1 : columns
for row = 1 : rows
if mod(col, 2) == 0 && mod(row, 2) == 0
% Pick red value.
mosaicedImage(row, col) = rgbImage(row, col, 1);
elseif mod(col, 2) == 0 && mod(row, 2) == 1
% Pick green value.
mosaicedImage(row, col) = rgbImage(row, col, 2);
elseif mod(col, 2) == 1 && mod(row, 2) == 0
% Pick green value.
mosaicedImage(row, col) = rgbImage(row, col, 2);
elseif mod(col, 2) == 1 && mod(row, 2) == 1
% Pick blue value.
mosaicedImage(row, col) = rgbImage(row, col, 3);
end
end
end
subplot(2,1,2);
imshow(mosaicedImage);
title('Mosaiced image', 'FontSize', 20);
  1 件のコメント
Setsuna Yuuki.
Setsuna Yuuki. 2020 年 11 月 8 日
編集済み: Setsuna Yuuki. 2020 年 11 月 8 日
Muchas gracias por la ayuda, me sirvió mucho esta respuesta :D

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

Community Treasure Hunt

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

Start Hunting!

Translated by