beyer matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
I have this code...which separates R G and B colors from a beyer image but when i try to display the three images i m getting black images is something missing in the code?
clc; I=imread('b2.bmp'); imshow(I); I=double(I); [M,N] = size(I);
red_mask = repmat([1 0; 0 0], M/2, N/2); green_mask = repmat([0 1; 1 0], M/2, N/2); blue_mask = repmat([0 0; 0 1], M/2, N/2);
R=I.*red_mask; G=I.*green_mask; B=I.*blue_mask;
답변 (2개)
Sean de Wolski
2011년 6월 21일
Try
imshow(R,[]);
You may just not be looking at the full range of values.
ADDENDUM per comment I'm not sure what you're trying to do (what makes a beyer image special?). If you're trying to mask the channels then your mask (for a typical rgb image) is wrong.
R = bsxfun(@times,reshape([1 0 0],[1 1 3]),I);
G = bsxfun(@times,reshape([0 1 0],[1 1 3]),I);
B = bsxfun(@times,reshape([0 0 1],[1 1 3]),I);
So that you're zeroing out the two channels (slices) that you don't want.
댓글 수: 3
Walter Roberson
2011년 6월 21일
beyer images have interleaved color channels, Sean -- but it isn't a straight forward R,G,B interleave: some channels occur more frequently than others.
Eric
2011년 6월 21일
I don't see anything wrong with your code, but I do wonder about your statement that you are "getting black images" with R, G, and B. Have you inspected the values of these arrays to know that they are zero everywhere, or are you looking at a visualization? If it's the latter, you might try imagesc() or the like.
You might also try something like:
R = I(1:2:end,1:2:end);
G1 = I(1:2:end,2:2:end);
G2 = I(2:2:end,1:2:end);
B = I(2:2:end,2:2:end);
G = (G1+G2)/2;
to index into I directly. Then R should be the actual red image (without interstitial zeros), and likewise for G and B. The way your code works R, G, and B are the same size as the original image. 75% of the values in R and B are zero and 50% of the values in G are zero.
Good luck, Eric
댓글 수: 2
Eric
2011년 6월 23일
Let me give an example:
G1 = I(1:2:end,2:2:end)
extracts the elements in rows 1,3,5,...,end and columns 2,4,6,...,end (where end denotes the last row or column, which is hopefully divisible by 2 in this case).
I tried to match my code to the 2x2 arrays in the repmat() functions in your original question. It looks like the Bayer matrix is of the form
R G R G
G B G B
R G R G
G B G B
So that's why I had R start at (1,1), G start at either (1,2) or (2,1), and B start at (2,2).
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!