Azzera filtri
Azzera filtri

for function with impixel

3 visualizzazioni (ultimi 30 giorni)
David
David il 31 Ott 2011
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 Commento
Image Analyst
Image Analyst il 31 Ott 2011
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.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 31 Ott 2011
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 Commento
David
David il 1 Nov 2011
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by