Azimuthally average line plot to 2D image
Ältere Kommentare anzeigen
Hi there,
I am trying to create a 2D image from a line profile.
Effectively, I would like to obtain its radial average and it must be centred in the middle of the image.
I have attached the x and y values of the plot.
I don't know where to begin.
Your help in anyway is appreciated,
Arthur
2 Kommentare
Mathieu NOE
am 23 Mär. 2021
hello
maybe I'm wrong but is the question about doin a kind of circle fit to your data (finding radial average ? )
Arthur Moya
am 23 Mär. 2021
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 24 Mär. 2021
Here is a simple brute force for-loop way. Simply create an image then scan every pixel location determining the radius from the center for that pixel and assigning the signal value there.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 18;
fprintf('Beginning to run %s.m ...\n', mfilename);
data = readmatrix('Chip_NPS_fit_x_y.txt');
r = data(:, 1);
signal = data(:, 2);
nexttile
plot(r, signal, 'b-');
title('Radial Profile', 'FontSize', fontSize);
grid on;
drawnow;
numElements = length(signal)
rows = ceil(2 * numElements / sqrt(2))
middlex = rows / 2;
middley = rows / 2;
grayImage = zeros(rows, rows);
for col = 1 : rows
fprintf('Assigning column %d.\n', col);
for row = 1 : rows
% Get the distance from the center of the image.
radiusInPixels = sqrt((col - middlex)^2 + (row - middley)^2);
% Scale it to be in the range 0 - 0.5, like r is.
% Find the signal value there.
radius = r(end) * radiusInPixels / numElements;
[~, index] = min(abs(r - radius));
grayImage(row, col) = signal(index);
end
end
nexttile
imshow(grayImage, []);
title('As a 2-D image', 'FontSize', fontSize);
% Maximize window
g = gcf;
g.WindowState = 'maximized';

1 Kommentar
Arthur Moya
am 24 Mär. 2021
Kategorien
Mehr zu Particle & Nuclear Physics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

