Radial averaging of 2-d tif image

21 ビュー (過去 30 日間)
Kevin Wang
Kevin Wang 2016 年 2 月 4 日
回答済み: Sergey Loginov 2021 年 11 月 5 日
I am looking to compute a radial average of a 2-d tif microscopy image.
I want to start from a given pixel as the center, go progressively radially and record the intensities of all the pixels lying on the locus of the circle of that radius. Out of all these, I want to compute a graph of radius vs. Intensity.
Any ideas? I am looking to create a .m file to do this. Thank you!

採用された回答

Image Analyst
Image Analyst 2016 年 2 月 4 日
編集済み: Image Analyst 2019 年 9 月 12 日
See my attached demo. Feel free to adapt, like to change the center or whatever. It gives the average radial profile within the blobs but you can use the same concept to do it over the whole image. The whole-image version is shown in the Answer below this one. Of course you could always just use ginput() to identify the center, compute the radiii, and use accumaray. Or just use a double for loop. So, there are several ways.

その他の回答 (3 件)

Image Analyst
Image Analyst 2016 年 2 月 4 日
編集済み: Image Analyst 2019 年 9 月 12 日
OK, so maybe that demo was too hard for you to adapt. Here is an easier, more straightforward demo using two for loops. It's easy to understand (as compared to accumarray which would probably be faster). See attached script below the image.
  1 件のコメント
Sergey Loginov
Sergey Loginov 2021 年 11 月 3 日
Dear ImageAnalyst,
Thanks for mentioning accumarray function here! At image sizes greater than 1000x1000 it is much much faster than this circle drawing stuff!!
Regards

サインインしてコメントする。


Hugo Trentesaux
Hugo Trentesaux 2019 年 2 月 7 日
編集済み: Hugo Trentesaux 2019 年 9 月 11 日
My version of the function :
function profile = radialAverage(IMG, cx, cy, w)
% computes the radial average of the image IMG around the cx,cy point
% w is the vector of radii starting from zero
[a,b] = size(IMG);
[Y, X] = meshgrid( (1:a)-cx, (1:b)-cy);
R = sqrt(X.^2 + Y.^2);
profile = [];
for i = w % radius of the circle
mask = (i-1<R & R<i+1); % smooth 1 px around the radius
values = (1-abs(R(mask)-i)) .* double(IMG(mask)); % smooth based on distance to ring
% values = IMG(mask); % without smooth
profile(end+1) = mean( values(:) );
end
end
  3 件のコメント
Hugo Trentesaux
Hugo Trentesaux 2019 年 9 月 11 日
You're right.
Sergey Loginov
Sergey Loginov 2021 年 11 月 3 日
Dear Hugo,
I have seen your are have answered quite a lot o these questions about the radial profiles with the same code. I have myself implemented it in a similar manner recently. However it is really much much faster to use accumarray function from MatLab!!
Regards
SL

サインインしてコメントする。


Sergey Loginov
Sergey Loginov 2021 年 11 月 5 日
Using accumarray is indeed so much faster!
function [Tics,Average]=radial_profile(data,radial_step)
%main axii cpecified:
x=(1:size(data,2))-size(data,2)/2;
y=(1:size(data,1))-size(data,1)/2;
% coordinate grid:
[X,Y]=meshgrid(x,y);
% creating circular layers
Z_integer=round(abs(X+1i*Y)/radial_step)+1;
% % illustrating the principle:
% % figure;imagesc(Z_integer.*data)
% very fast MatLab calculations:
Tics=accumarray(Z_integer(:),abs(X(:)+1i*Y(:)),[],@mean);
Average=accumarray(Z_integer(:),data(:),[],@mean);
end
Sergey Loginov (2021). Very Fast Radial Profile (https://www.mathworks.com/matlabcentral/fileexchange/101480-very-fast-radial-profile), MATLAB Central File Exchange. Retrieved November 5, 2021.

カテゴリ

Help Center および File ExchangeBiomedical Imaging についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by