Borrar filtros
Borrar filtros

Plotting where two arrays meet

3 visualizaciones (últimos 30 días)
Steven Manz
Steven Manz el 28 de Mayo de 2020
Editada: Steven Manz el 28 de Mayo de 2020
Hi there,
I am hoping to create an array that can be plotted. This array should just simply show the 2D parabola created where two arrays meet. For instance, I have two arrays: z and zpaper. These two arrays meet at a certain spot in space and create sort of a parabola at their intersection. I would like to create an array that just holds these values so the information can be analyzed as a 2D plot. Considering the code, I ran it for two images, so zpaper is for 1 image, whereas z is for the other. This was not coded in, I simply changed the variable name z to zpaper after running the first image and after running the second image, I left the variable as z. Here is the code:
raw_image = imread(filename)';
figure()
mesh(raw_image)
avg = sum(sum(raw_image))/nnz(raw_image);
M1 = raw_image < avg;
[y1,x1] = ndgrid(1:size(M1, 1), 1:size(M1, 2));
centroid = mean([x1(M1),y1(M1)]);
x1 = nnz(M1(floor(centroid(1)),:));
y1 = nnz(M1(:,floor(centroid(2))));
avg = mean(mean(raw_image(centroid(1)-x1/2:centroid(1)+x1/2,centroid(2)-y1/2:centroid(2)+y1/2)));
std = std2(raw_image(centroid(1)-x1/2:centroid(1)+x1/2,centroid(2)-y1/2:centroid(2)+y1/2));
var = std.^2;
threshold = avg + 2.3*std;
M = raw_image < threshold;
raw_image = raw_image.*uint8(M);
figure()
mesh(raw_image)
figure()
imshow(raw_image*5)
fractionofdisc = 0.1:.01:1.0;
ny = length(fractionofdisc);
mult = double(prctile(raw_image(raw_image ~= 0),[5 95], 'all'));
multiplier = linspace(mult(1),mult(2),ny);
nx = length(multiplier);
if nx ~= ny
error('In house error. The length of the multiplier and fraction of disc must be the same!')
end
[X,Y] = meshgrid(fractionofdisc, multiplier);
z = zeros(nx,ny);
for i = 1 : ny
y = fractionofdisc(i);
for k = 1 : nx
x = multiplier(k); % have to create a variable for the x axis of plot
%n = mean(mean(raw_image(raw_image ~= 0)))*x; % changing data type may not be necessary
Mp2 = raw_image > x;
sum_Mp2 = sum(Mp2);
sum_sum_Mp2 = sum(sum_Mp2); % algorithm stops at a fraction of this number
cumsum = 0;
% While loop needed to sweep across the x values until it reaches
% cumsum
while cumsum < y*sum_sum_Mp2
z(i,k) = z(i,k) + 1; % column index
cumsum = cumsum + sum_Mp2(z(i,k));
end
end
end
figure()
mesh(X,Y,z,'edgecolor','r')
hold on
mesh(X,Y,zpaper,'edgecolor','b')
hold off
% equal = zpaper == z;
equal = ismembertol(zpaper,z);%,'DataScale',0);
figure()
mesh(equal)
At the bottom here, I was attempting to see if I could grab the places where the two arrays met and maybe with a tolerance to create a curve without jumps. The figures in question as well as the raw images are attached.
Thank you ahead of time!!

Respuestas (0)

Categorías

Más información sobre Visual Exploration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by