필터 지우기
필터 지우기

beyer matrix

조회 수: 3 (최근 30일)
eric nunes
eric nunes 2011년 6월 21일
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;
  댓글 수: 1
Oliver Woodford
Oliver Woodford 2011년 6월 22일
I think you mean Bayer.

댓글을 달려면 로그인하십시오.

답변 (2개)

Sean de Wolski
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
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.
Sean de Wolski
Sean de Wolski 2011년 6월 21일
Ahh. Ignore the Addendum then...

댓글을 달려면 로그인하십시오.


Eric
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 nunes
eric nunes 2011년 6월 22일
Thanks eric..this was of great help...but i need to ask you one more thing the short code that you have given to directly index into I what does it exactly do i mean wat is 1:2 , 2:2 .....and for this code is the beyer matrix bggr or rggb
Eric
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).

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by