for function with impixel

조회 수: 3 (최근 30일)
David
David 2011년 10월 31일
I have been using the following code to create a matrix of a range of pixel RGB values. The code works fine if y and x are set to start at 1 however, if I ask it to start at 2 or anywhere else it gives me a load of zero values for x = y = 1 even though I didn't ask for them.
What I would like is impixel to make a matrix just of the RGB within the range. How do I make impixel work in the range set? Or what I thought was set. Thanks.
A = imread('image.jpg');
for y = 2:10;
for x = 2:10;
B(:,x,y) = impixel(A,x,y);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Comment added 08.50am 01/11/2011
Thanks for the replies so far.
What I would like to do is used regionprops(C,'boundarybox') of an image, using the box as my range of pixels. Then with the above code obtain the RGB values for just the box region. The box would set my x and y values. The image is 480 by 720.
The boundary that I want matlab to pick up is a card board printed image of a black cross, on white paper. The reason for this is so I can find out the ideal range of values of the card (my reference). Once I have my reference I can record moving the camera and compare how the quality changes in a mathematical way.
I've purposely simplified the variables in the above code to make my problem clear. X is the amount of pixels along the X direction, Y is the amount of pixel along the Y direction.
Hope this makes it clearer.
  댓글 수: 1
Image Analyst
Image Analyst 2011년 10월 31일
Define, exactly, what is "range of pixel RGB values." And tell me what x and y represent. Like, why would x go from 2 to 10 - apparently it's not a position, or is it? If you just want to generate a range you can use linspace(). If you want to extract the 3D color gamut from a hand drawn, or otherwise defined, region then say that. Or if you want histograms, then say that.

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

채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 31일
You do not initialize B, so when you assign in to it starting at (:,2,2) then (:,1,:) and (:,:,1) are going to have the default value 0.
Perhaps you want
B(:,x-1,y-1) = impixel(A,x,y);
  댓글 수: 1
David
David 2011년 11월 1일
This works and helps to get rid of the zeros. However, the RGB values lose there pixel placements. It doesn't matter I suppose but would there be another way to have the RGB values with there pixel placement, without having the zeros for (1,1) and so on.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by