MATLAB contains demosaic() function to convert Bayer pattern encoded image to true color, does it contain opposite function as well?
조회 수: 18 (최근 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?
댓글 수: 0
답변 (2개)
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.
2020년 11월 8일
편집: Setsuna Yuuki.
2020년 11월 8일
Muchas gracias por la ayuda, me sirvió mucho esta respuesta :D
Joseph Majdi
2024년 2월 27일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!