MATLAB contains demosaic() function to convert Bayer pattern encoded image to true color, does it contain opposite function as well?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (2)
Image Analyst
el 15 de Ag. de 2017
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 comentario
Setsuna Yuuki.
el 8 de Nov. de 2020
Editada: Setsuna Yuuki.
el 8 de Nov. de 2020
Muchas gracias por la ayuda, me sirvió mucho esta respuesta :D
Joseph Majdi
el 27 de Feb. de 2024
It's probably easiest to use index notation to "subsample" the RGB in every 2nd by 2nd pixel into that sub-color, ie:
originalRGB = imread('peppers.png');
pepperMosaic = zeros(size(originalRGB,[1 2]),'uint8');
pepperMosaic(1:2:end,1:2:end) = originalRGB(1:2:end,1:2:end,2);%Green Pixels (1 of 2)
pepperMosaic(2:2:end,2:2:end) = originalRGB(2:2:end,2:2:end,2);%Green Pixels (2 of 2)
pepperMosaic(2:2:end,1:2:end) = originalRGB(2:2:end,1:2:end,1);%Red Pixels
pepperMosaic(1:2:end,2:2:end) = originalRGB(1:2:end,2:2:end,3);%Blue Pixels
figure; imagesc(originalRGB); title('Original Peppers'); axis equal tight; colormap gray
figure; imagesc(pepperMosaic); title('Peppers Bayer GBRG'); axis equal tight; colormap gray
figure; imagesc(demosaic(pepperMosaic,'gbrg')); title('Reconstructed Peppers from Mosaic'); axis equal tight;
This assumes you want the GBRG mosaic pattern, and you can adjust the indices for GRBG, BGGR, or RGGB (the other bayer formats matlab recognizes in the demosaic function).
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!