unifrnd, matrix

Hi friends, can you help me out with this
I have a matrix(or a frame(image) in my case) called 'z', say its a 3x3 frame.
x = [1.2, 0.45, 0.2, 0.25, 20]';
n=3;
m=3;
blur = 0.7;
a = 3.*randn(n,m);
for i=1:n
for j=1:m
if i-x(1) < 3 && j-x(3) <3
h(i,j) = x(5)/(2 * pi * (blur^2)) * exp(-((i-x(1))^2 + (j-x(3))^2)/ (2* (blur^2)))
else
h(i,j) = 0
end
end
end
z = a + h;
So, 'z' will be a 3x3 frame having certain values for the 9 pixels.
'x' is a state vector having are [position along x-axis, velocity along x-axis, position along y-axis, velocity along y-axis, Intensity].
So the pixels in frame 'z' that fall in the vicinity of the position given by 'x' in x-y direction ie x(1) & x(3) will have higher values(Intensity than others)
now, what I want is, the position of the particles should be initialized from the distribution q(x,y | z) is a uniform density over those regions in 'z' for which z(i,j) > T
T = threshold = 2
I need to draw values from that distribution.
Can you help me out with this?

4 Comments

Image Analyst
Image Analyst on 16 Oct 2011
Probably could, if I could figure out what you mean. I fail to see why z would be higher at locations where x and y are listed in your 'x' state vector. Why would that be? What guarantees or forces that? Also, shouldn't this really have been continued on your original thread http://www.mathworks.com/matlabcentral/answers/18395-uniform-density-matrix
PChoppala
PChoppala on 16 Oct 2011
Well, if you run could the code I put in, you can see that 'h' will be a matrix that has more intensity at locations given by (x(1),x(3)). It can be obtained from the Gaussian expression where we plug in x(1), x(3) and x(5).
a is just noise
So, z = a+h(noise + signal)
Now I want the vicinity of 'z' where it crosses the threshold, and then initialize a new position.
this new position will be drawn from a uniform density over those regions, where the pixel values(intensities) are greater than T=2
I posted it again, because I could not get a reply for a long time from any of the Matlab friends, and I assume, with this I should be able to run my program correctly, for which I am due tomorrow.
PChoppala
PChoppala on 16 Oct 2011
z =
0.8097 -0.2496 0.0621
5.8031 -2.2792 -0.1705
3.5348 11.1277 -3.6788
I have a better way of asking, my friend!
Consider the above matrix.
I want to find the indices of the rows in which atleast one element is greater than 2
Similarly, I want to find the indices of the columns in which atleast one element is greater than 2
Please help
Image Analyst
Image Analyst on 16 Oct 2011
Well I didn't see it because x(1) = 1.2 and x(3) = 0.2 and you can't have a z value at the (1.2th, 0.2th) location, unless you make another array that is interpolated to give values there. But whatever...see my answer below, which answers your last question and thankfully doesn't depend on understanding the first part.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 16 Oct 2011
Just do
[rows columns] = find(z>2);
The find() function is usually one of the first ones people learn (along with min, max, mean, and sum). You'll also need sum if you want to find which rows or columns have more than 2 elements above the threshold. It's a really really easy one-liner. Write back if you can't figure it out.

3 Comments

PChoppala
PChoppala on 16 Oct 2011
I used
Arr=[];
for n1=1:n
p = find(h(n1,:)>2);
if isempty(p) == 0
Arr = [Arr n1];
end
end
Brr=[];
for m1=1:m
q = find(h(:,m1)>2);
if isempty(q) == 0
Brr = [Brr m1];
end
end
Any better solution?
PChoppala
PChoppala on 16 Oct 2011
n=rows=3
m=columns=3
Image Analyst
Image Analyst on 16 Oct 2011
Not sure what all that was. This is what I was thinking:
columnsWithMoreThan2 = sum(z>2, 1);
rowsWithMoreThan2 = sum(z>2, 2);

Sign in to comment.

Asked:

on 16 Oct 2011

Community Treasure Hunt

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

Start Hunting!