Contribution from all pixels to 1 pixel

Hello all,
I've got a series of 2D image slices, with each pixel being a measure of intensity. I'm looking to work out the contribution from all pixels to each individual pixel using a function relating the intensity of each pixel to the distance from the contributing pixel. Would anyone know a fast efficient way to do this? I've tried a function using cumsum but its not going to plan
Thanks
Jim

Risposte (1)

Image Analyst
Image Analyst il 2 Ago 2012
Why do you think that all other pixels have any influence on one single pixel? Do you know your image is , say, blurred with a large point spread function? If so, have you tried inverse filtering or wiener filtering or richardson-lucy deconvolution?

12 Commenti

Thanks for your reply. Rather than deconvolve the image with a known point spread function, each voxel in my 3D image is affected by an exponential-type function, which is dependent on the distance between the voxel (each side-by-side voxel is 4.1 mm apart). I'm using it to work out a total radiation dose in each voxel, and this voxel's total radiation dose requires the contribution from all other voxels.
I think you're going to have to do that by scanning your volume and doing the calculations. It would take far too much memory to do something like bwdist() for every pixel in the volume and store it. Maybe you can use bwdist as you scan and get the distance transform for every pixel, but you can't store the EDT for every voxel, nor do you need to.
That will happen, even for mathematically perfect scaling. Just look at your diagrams and imagine what's going to happen to that bay as your "constant distance" increases. You're going to close off that bay. You can use imresize to maintain the shape at a larger resolution but it won't be a constant distance anymore.
Thanks for tip, I'll give it a try. Would it be far less computer-intensive to use a nearest-neighbour type approach i.e the contribution from 8 nearest neighbours? Also, would you know any predefined functions for doing something like this or would I still have to loop through and manually do the calculations?
Thanks
Jim
I tried the following function and I ran out of memory for a single image, hence the reason I was asking about a nearest neighbour approach
A = double(act_map(:,:,65));
w = size(A,1);
h = size(A,2);
i=1;
for pxRow = 1:h
for pxCol = 1:w
for r = 1:w
for c = 1:h
d(c,r) = sqrt((r-pxRow)^2 + (c-pxCol)^2);
end
end
i = i+1;
end
end
That doesn't look right. You've calculating a new d array for every pixel. You're overwriting it because its indexes don't depend on pxRow and pxCol. Maybe I'm misunderstanding what you want but if you want the distance of every pixel to every other pixels, then...well let's just take the upper left pixels and let's say you have a million pixels. So for that upper left pixel you have a million distances. And you have another million distances for the pixel next to it, and so on. Every one of the million pixels will have a million distances. So the grand total is a billion distances, or about 8 GB of memory. I see no reason why you need to store all of those in memory at one time.
Good point, indeed I certainly don't need that many distances. I've done some calculations and I could easily settle for the distance from the 8 (or similar number) nearest neighbours. Any idea how I might achieve this?
Well I think you know what those are. 4 of them will be 1 and 4 of them will be sqrt(2).
And this would seem to be a good application of conv2() with a square kernel of the distances away from the center pixel. Something like
s2r = 1/sqrt(2);
kernel = [s2r, 1, s2r; 1, 0, 1; s2r, 1, s2r];
Jim O'Doherty
Jim O'Doherty il 6 Ago 2012
Modificato: Jim O'Doherty il 6 Ago 2012
OK, thanks for the tip. I've worked out that I will require the contribution from 26 nearest neighbours (1 voxel in the centre of a rubix cube-style arrangement of 27 voxels). I now know the distances between my nearest neighbours, but I am still confused with the indexing
Essentially what I need to do is
if distance from a neighbour to central voxel is 1 unit, add the value of this nearest neighbour voxel on to the value of the central voxel
elseif the distance is sqrt(2) add the value of this nearest neighbour voxel to the value of the central voxel
I then need to perform this loop for every voxel in the image
I guess in summary , I need to have a 3x3x3 kernel that changes its kernel values dependent on the values of the nearest neighbour voxels
Perhaps something with the convn function, or possibly "arrayfun"?
kernels specify a pattern of multiplications and additions, that are to be used in a "sliding window" manner.
When the distances are sqrt(2) do you want to add the full voxel value to the central voxel, or do you want to add the value divided by sqrt(2) ?
If you want to add the full voxel value, then your kernel would, I think, be simply ones(3,3,3)
Jim O'Doherty
Jim O'Doherty il 8 Ago 2012
Modificato: Jim O'Doherty il 8 Ago 2012
OK thanks, I'm getting there as I now understand your tip, as well as my problem a bit better. I think my situation is a little bit more complex (although hopefully I'm wrong).
So for my "kernel" (or however else I can do this), my distances to each nearest neighbour are either 1 unit or sqrt(2) units.
Next for each nearest neighbour voxel, I need to multiply a number by the voxel value (say 3 times the voxel value if it is 1 unit away, and 5 times the voxel value that is sqrt(2) units away). For each voxel in the kernel, the final number needs to be added on to the value of the central voxel.
Would I still be able to structure a kernel to suit this requirement?
Thanks again for your help Jim

Accedi per commentare.

Richiesto:

il 2 Ago 2012

Community Treasure Hunt

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

Start Hunting!

Translated by