Getting the values ​​of the pixels inside the sphere of radius (r1) and center (x1, y1, z1).

1 次查看(过去 30 天)
I want to get the values ​​of the pixels inside the sphere of radius (r1), center coordinates (x1, y1, z1) in the 3D image (xyz).
As a matter of fact, I'm not interested in the values ​​of individual pixels and want to get statistics such as mean and SD.
Since there is not one sphere, but hundreds or more, so I'm looking for an efficient way to quantify them.
I have the values ​​of radius (r1, r2, r3 ...) and center coordinates ((x1, y1, z1), (x2, y2, z2), (x3, y3, z3) ...) .
Please tell me how to do it easily.
If my explanation is inadequate, please ask and I'll get back to you soon.

采纳的回答

Walter Roberson
Walter Roberson 2020-11-6
Supposing you have a 3D grid Pixel_x, Pixel_y, Pixel_z, and you have Center_x, Center_y, Center_z, and Radii
Center_x_row = reshape(Center_x, 1, []);
Center_y_row = reshape(Center_y, 1, []);
Center_z_row = reshape(Center_z, 1, []);
Radiisq_row = reshape(Radii, 1, []).^2;
Pixel_x_col = reshape(Pixel_x, [], 1);
Pixel_y_col = reshape(Pixel_y, [], 1);
Pixel_z_col = reshape(Pixel_z, [], 1);
distssq = (Pixel_x_col - Center_x_row).^2 + (Pixel_y_col - Center_y_row).^2 + (Pixel_z_col - Center_z_row).^2;
%at this point, rows correspond to individual pixels, and columns correspond to sphere centers
%and distssq is distances squared
pixel_within_sphere = distssq <= Radiisq_row;
num_pixel_within_sphere = sum(pixel_within_sphere); %single row, one column per sphere center
and now you can take mean(num_pixel_within_sphere) and so on.
  3 个评论
Walter Roberson
Walter Roberson 2020-11-6
Average color intensity in a grayscale image does not appear to make sense, unless you are taking about brightness as color. If so then
grayscale_col = Grayscale_Intensities(:);
pixel_within_sphere = distssq <= Radiisq_row;
num_pixel_within_sphere = sum(pixel_within_sphere); %single row, one column per sphere center
weighted_gray = pixel_with_sphere .* grayscale_col;
total_gray = sum(weighted_gray, 1);
mean_gray = total_gray ./ num_pixel_within_sphere;
std_gray = sqrt(sum((weighted_gray - mean_gray).^2 .* pixel_with_sphere,1) ./ (num_pixel_within_sphere - 1));
I used N-1 weighting instead of N weighting, as is appropriate for a finite population.
Yusaku Ohta
Yusaku Ohta 2020-11-6
Sorry for the late reply.
Thank you for your very smart response.
It took me a while to figure it out because it was too smart!
It's amazing how easy it is to do.
I learned a lot, thank you.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by