Mean radial profile from a given point
41 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm quite new using Matlab and I want to write a program to do the following things:
1- from the attached file I have, I want to locate the coordinate center of the irradiation (ideally, with an histogram to avoid a trouble with 1 pixel). Note that it is a circular irradiation in this example but it can be squared too.
2- from that point, I would plot the mean radial profile (over 360°, thanks to the symmetry), and compare to the mean profile plot from X and Y direction (on that way, is it possible to modify the band width when plotting the profile?)
I find some examples here but they didn't help me...
Thanks in advance !
0 个评论
回答(3 个)
Hugo Trentesaux
2019-2-7
To find the center, check regionprops Matlab function, it has a lot of features.
To compute the radial profile, you can program a function like this :
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);
[X, Y] = 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
0 个评论
Sergey Loginov
2021-11-5
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.
0 个评论
yanqi liu
2021-11-6
clc; clear all; close all;
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/203087/Irradiation.JPG');
bw = imbinarize(rgb2gray(img), 'adaptive','ForegroundPolarity','dark','Sensitivity',0.6);
bw = ~bw;
bw = imfill(bw, 'holes');
bw = imclearborder(bw);
bw = bwareafilt(bw,1);
figure; imshow(bw);
be = bwperim(bw);
[y,x] = find(be);
data = [x(:) y(:)];
[Tics,Average]=radial_profile(data,1);
function [Tics,Average]=radial_profile(data,radial_step)
% use:https://ww2.mathworks.cn/matlabcentral/fileexchange/101480-very-fast-radial-profile
%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)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!