Calculate distance-to-agreement of two matrices?

Calculate distance-to-agreement of two matrices?

Post by Ian Cowle » Sat, 08 Nov 2003 00:19:11



I wonder if any of you MATLAB whizzes out there can help me with this...

I have two 2-D matrices of the same size.  They show distribution of
radiation in a target.  The distributions are pretty much smooth, and mostly
hill-like, i.e. maximum is near the centre.  Values range from 0 to 150
double-precision values.

The two matrices look very similar, but are generated from a simulation with
slightly different inputs.  One way to compare the distributions is by
absolute or relative difference - that's easy.  Another way is
distance-to-agreement (DTA).

DTA works like this: For each position in matrix 1, we want the distance
from the corresponding position in matrix 2 to the nearest position in
matrix 2 with the same value as the posiiton in matrix 1.  Basically, we
have to plot contours of the distributions, and the contours have to match
within a certain distance tolerance, and I'm looking at how to calculate
that distance.

The only way I've yet to come up with is to calculate the distance to every
position, and it's value, then take the nearest one of the same value (or
within a 0.1 value threshold).  However, this is order n-squared cacluation
time, and the matrices can get quite large (400x400 or so).

Any quicker ways of doing it?

--
Ian Cowley (Not Reverend)  - Perfecting pedantry through practice
  Check www.iancowley.co.uk for contact details!
"Some people don't understand statistics" - Ciaran Byrne

 
 
 

Calculate distance-to-agreement of two matrices?

Post by NC » Sat, 08 Nov 2003 00:43:32


You can see my solution at:

 <http://doselab.sf.net/>

Basically, I just used IMCONTOUR a lot, and found that you only need
to travel in 5-10 cGy steps to produce results as accurate as 1 cGy
steps (I use GRIDDATA to fill in the gaps). This assumption reduces
the computation time to around 10-40 seconds. I tried more clever
ways, but they were either less accurate (solutions that didn't use
IMCONTOUR and thus could miss interpolated points) or as accurate and
required the same amount of time. I'm sure writing the DTA algorithm
in C would help. There's probably a better solution that I'm
missing, but the above approximation seems to work well and is done
fairly quickly.

You could also try taking absolute differes of the two images after
shifing them one pixel at a time, up to 5 mm or so. Again, this will
miss interpolated points, but as you noted, the DTA function is
generally smooth.

 
 
 

1. How to calculate the mean for two matrices, pixel by pixel?

Hello,

I have two matrices made of pixels.

I want to create a new matrix which would contain the mean value of
each pixel from the 2 matrices.

Then save the new matrix as an ASCII file(matrix), not as a vector.

How would it be possible to make a generic(general code) for each two
same files?
 like from 12 and 15,make 10
22 and 25, make 20
32 and 35, make 30
42 and 45, make 40
....

for example:

Matrix 12                   matrix 15

200 203 201 200            201 201 207 200
201 200 202 200            200 203 202 209
... ... ... ...            ... ... ... ...    

New Matrix 10

200.5 202 204 200
200.5 201.5 202 204.5
...   ...   ... ...  

I wrote the following code but it gives me error messages that i do
not know how to fix.

load image0012.dat
load image0015.dat
image1=image0012(1:400,1:650);
image2=image0015(1:400,1:650);

for i=1:400
    for j=1:650
        if image1(i,j)>180 & image2(i,j)>180
            mu(i,j)=mean(image1(i,j),image2(i,j));
        else
            mu(i,j)=-9999;
            image_new(i,j)=mu;
            save mu.dat irn -ascii
        end
    end
end

The error messages are:

??? Error using ==> sum
Dimension argument must be a positive integer scalar.

Error in ==> C:\MATLAB6p5\toolbox\matlab\datafun\mean.m
On line 28  ==>   y = sum(x,dim)/size(x,dim);

Error in ==> C:\Documents and Settings\...document1.m
On line 13  ==>             mu(i,j)=mean(image1(i,j),image2(i,j));

Thank you for your time and consideration.

2. Win2k server locking up

3. How to calculate the distance from a point to a curve?

4. IDE CDROM and Netware 4.1

5. Calculate Average Nearest neighbor distance

6. My spectrum 128+ is dead, long live the SAM coupe

7. Calculating distance in 3D

8. HP970C paper settings

9. Shortest distance between two surfaces

10. GSVD of two large matrices, each of which the product of two others

11. Computation of distance between points in two vectors.

12. how to find distances between two vectors

13. Dendrogram from imported distance matrix