Computing pixels value(Uk,Uj) from U -Image in YUV color Space

Hi everyone
I want to compute the pixel values let say Uk and Uj from UImage.Here is my code in which I am doing indexing.
UImage=imread(Uimage);
B=ones(length(UImage));
slidingwindow=conv2(B,UIimage,'same');%this part computes only centre pixels.
[pixelrow pixelcol]=size(slidingwindow);%Pixelrow and pixelcol are center pixels of window
for windrow=-1:1
row=pixelsrow+windrow;
for windcol=-1:1
col=pixelscol+windcol;
%% here I need some piece of code further May be Uk=UImage(row,col)???????????
end end

1 Comment

Hello Sir,
I am working on the same sheet. Please can i have your code and we may help each other :D
I will be grateful Have a nice day

Sign in to comment.

Answers (2)

To get the pixel values of a gray scale image
I = imread('cameraman.tif');
x = 20; y = 30;
Ixy = I(y, x);
To get the G pixel value of an RGB image
I = imread('peppers.png');
IGxy = I(y, x, 2);
Same should work for your U image if you have stored just the U channel or all three channels in your image.

8 Comments

My Dear this is very basic concept.Pleas read my question properly as I need something else.I have already got U Image now I need to compute the pixel values from different locations thats why I applied sliding window concept..Please read it properly thanku.
If you want to compute some function, e.g., mean on sliding blocks, you can use
M = colfilt(I, [3 3], 'sliding', @mean);
If this does not help you, please ask more precisely what you want to compute.
Ok for your understanding I explain it more clearly..
I want to compute Gussian kernel of UV image in YUV space.I have separated out UV image form YUV space.Now I want to compute Gaussain Kernel by using the formulae below.
DU=Uk-j and DV=Vk-Vj
Gaussian=1./(2*sigma*sigma)*exp(-Du*Du+Dv*Dv./(2*sigma));
Thats why I need to compute the pixel values of U image from j and k location.therefore I used sliding window concept here but I am stuck on this point.
Thanks
First you get the n x n subimages Uk and Vk from U and V at position x, y
Uk = U(ind1, ind2);
Vk = V(ind1, ind2);
with
ind1 = y-n/2:y+n/2;
ind2 = x-n/2:x+n/2;
The contribution of these subimages to bin j asscociated with some fixes colors Uj, Vj is then
dU = Uk(:) - Uj;
dV = Vk(:) - Vj;
Gj = Kj*exp(-(Du.^2+Dv.^2)/(2*sigma^2));
with normalization coefficient Kj.
can you please tell me what is x,y and n and how to compute them?
I have two images U and V.can you please tell me how can we compute ind1 and ind2? thank you.
As I applied the sliding window concept in my code refered by image analyst.But I did not see any of sliding window in your piece of code.Can you plz explain little bit more.
Thank you.
and what is Uj and Vj and how did you compute it?
I assume that you refer to the paper http://philippe.noriega.free.fr/fichiers/visapp06.pdf
Then x and y are the location in the image where you compute your histograms. n = 12 is the size of your subwindow that is applied with a gap of 3 to your image.
To slide your window, use
gap = 3;
for x = 1:gap:size(I, 1)
for y = 1:gap:size(I, 2)
ind1 = y-n/2:y+n/2;
ind2 = x-n/2:x+n/2;
And for each location you need a third loop over the number of bins in your histogram
for j = 1:Nbins
dU = Uk(:) - Uval(j);
dV = Vk(:) - Vval(j);
Gj = Kj*exp(-(Du.^2+Dv.^2)/(2*sigma^2));
CH(x, y, j) = Gj;
end
end
end

Sign in to comment.

Your code is all wrong. Try this:
UImage=imread(Uimage);
windowSize = 5;
sigma = whatever.....
kernel = fspecial('gaussian', windowSize, sigma);
slidingwindow=conv2(UIimage, kernel ,'same');
You don't need double for loops after that - conv2 does the sliding window filtering so it's already done. No need to try to do it again manually.

9 Comments

Yes.this work fine but as you told in your previous answer here (<http://www.mathworks.co.kr/matlabcentral/answers/63950-computing-color-gaussian-kernel)>.
we need to compute Uk and Uj pixel from different locations thats why I was working on it.So is this code the Color Gassian kernel is (slidingwindow=conv2(UImage,kernel,'same')) ?So where is Uj and Uk?
As slidingwindow contains the centre part...
Thanks ....
Based on one of AlgorithmAnalyst's previous question I think that his question refers to the local kernel color histogram algorithm described in http://philippe.noriega.free.fr/fichiers/visapp06.pdf
Yes you are right.This is what I am implementing.But confused too much As Image Analyst code I cannot see Uk and Uj.May if I am not wring these two pixels location are in sliding window.?
As far as I have understood the algorithm, you compute histograms at different image locations x, y. The histograms are by counting the frequency of Nj colors (Uj, Vj) in a 12 x 12 window around (x, y). To make the counting more robust, you increment the (Uj, Vj) bin not only if you encounter the color (Uj, Vj) in your 12 x 12 window, but you compute a Gaussian weighted similary between your 12 x 12 patch and the color (Uj, Vj). See my code I sketched above.
Yes and I have commented on your question how to compute these locations xy and n and how to compute Uj and Vj this is my question.But I think Image Alalyst has solved it by directly calling fspecial and conv2 finctions in Matlab.
Thanks for your concern..
The conv2 code essentially is 4 nexted for loops, the outer two move the window along - they scan the image over all rows and all columns. At a particular row and column inside those two loops there is a nested pair that scans over the pixels in the window (kernel) that has your Gaussian weights. Let's say these loops are over rw and cw. For example, if you have a 3 by 3 window, the outer loops will (eventually) get you to row,column 135, 154. So we need to scan a window around there from row 134 to 136, and from column 153 to 155. So when it's doing that, j and k are calculated from row and rw and column and cw. Specifically if rw goes from -1 to +1, then j = row + rw, and k = column + cw. So j and k would start out at (134, 153), then go to (135,153) then to (136,153) then to (134, 154) and so on until it visits all 9 locations in the window centered around (135, 155). But when you're taking the U value from (134,154), you don't have a Gaussian with those values because the Gaussian is just a 3x3 window so the value of the Gaussian at that upper left window pixel would be the Gaussian value at (-1, -1), in other words, the Gaussian value at a distance of sqrt(2) away from the center of the Gaussian. I hope that explains it better.
So slidingwindow is the required color gaussian kernel?i dont need further calculation?
Correct, but I haven't really tried to understand what the algorithm does. You're just blurring the U channel. Not sure if that's part of the algorithm or not - I'm just going by what you said.
Yeah. That's so interesting.In the color Gaussian kernel part of the algorithm two other pixels values from i and j locations are computed and they are VJ and Vk respectively.So I think they are taking just UV image from YUV colorspace by ignoring Y channel and computing the color gaussain kernel in UV color space.But anyway thanks for your time and concern.
Thanksssss......cheers..

Sign in to comment.

Categories

Asked:

on 20 Feb 2013

Commented:

on 20 May 2014

Community Treasure Hunt

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

Start Hunting!