Linear fit for a intensity plot (surface plot)

Hi,
I want to find the rotation angle of this plot. (Angle with respect to the horizontal axis.)
In order to do that I'm thinking of doing a linear fit and get the gradient. Something like this:
How can I do a linear fit to this surface plot?
Thank you.

5 comentarios

Mathieu NOE
Mathieu NOE el 8 de Mzo. de 2021
hello
do you have the data or do you have only this picture ?
S
S el 8 de Mzo. de 2021
Hi,
I have the data.
So first attempt here .... but my linear fit seem a bit off
I smoothed first a bit the data and search for peak location at each row.
the red line is the line of maximum values , but visually it seems not truly aligned with our expectation
data = readmatrix('Rotation.txt');
[m,n] = size(data);
% [val,ind] = max(data,[],'all');
dataS = smooth2a(data,1,7);
x=0;
y=0;
k=0;
for ci = 15:40
k = k+1;
[val,ind] = max(dataS(ci,:));
x(k) = ind;
% zz= cumtrapz(dataS(ci,:));
% x(k) = interp1(zz,1:109,max(zz/2));
y(k) = ci;
end
figure(1),imagesc(dataS)
hold on
plot(x,y,'r')
hold off
axis('xy');
% axis('equal');
slope = mean(diff(y))./mean(diff(x));
angl = atan(slope) % in radians
Image Analyst
Image Analyst el 8 de Mzo. de 2021
Unrecognized function or variable 'smooth2a'.
Error in test5 (line 14)
dataS = smooth2a(data,1,7);
S
S el 8 de Mzo. de 2021
Hi,
I searched and download this smooth2a.m file.
Then it worked. I'm trying edit this code for a linear fit can get 95% confidence interval for gradrient.
Thanks

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 8 de Mzo. de 2021
regionprops() fits the image to an ellipse and returns the center and angle in degrees. Try this:
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 long g;
format compact;
fprintf('Beginning to run %s.m ...\n', mfilename);
fontSize = 15;
data = readmatrix('Rotation.txt');
[rows, columns] = size(data);
subplot(2, 2, 1);
imshow(data, []);
impixelinfo
axis('on', 'xy');
title('Original Data', 'FontSize', fontSize);
subplot(2, 2, 2);
histogram(data);
grid on;
title('Histogram of Data', 'FontSize', fontSize);
mask = data > 30;
% Take largest blob only.
mask = bwareafilt(mask, 1);
subplot(2, 2, 3:4);
imshow(mask);
axis('on', 'xy');
title('Mask', 'FontSize', fontSize);
% Get the angle (Orientation) using regionprops
props = regionprops(mask, 'Orientation', 'Centroid')
angle = -props.Orientation;
xCenter = props.Centroid(1)
yCenter = props.Centroid(2)
fprintf('The angle is %.2f degrees.\n', angle);
x = 1 : columns;
slope = tand(angle)
y = slope * (x - xCenter) + yCenter;
hold on;
plot(xCenter, yCenter, 'r+', 'LineWidth', 2, 'MarkerSize', 30);
plot(x, y, 'r-', 'LineWidth', 2);
caption = sprintf('Angle = %.2f degrees. Slope = %.2f. xCenter = %.1f. yCenter = %.1f', ...
angle, slope, xCenter, yCenter);
title(caption, 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized'
props =
struct with fields:
Centroid: [50.5731822474032 28.7478753541076]
Orientation: -17.0388178322049
xCenter =
50.5731822474032
yCenter =
28.7478753541076
The angle is 17.04 degrees.
slope =
0.30647166070947

2 comentarios

S
S el 8 de Mzo. de 2021
Thank you very much.
S
S el 9 de Mzo. de 2021
Editada: S el 9 de Mzo. de 2021
Hi,
Is it possible to get the 95% confidence interval of the 'Orientation'.
Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Geographic Plots en Centro de ayuda y File Exchange.

Preguntada:

S
S
el 8 de Mzo. de 2021

Editada:

S
S
el 9 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by