How to plot a 2D histogram with data for x, y and z intensity values (without mesh grid)

5 views (last 30 days)
I need to plot a 2D projection image (data is attached), I previously used the mathworks code below but it created the image in the format of a 'matlab.primative.graphic.image' which cannot be analysed further. I have attached an image of what I am trying to recreate in matlab, here is what the 2D image looked like as an output from the .root software. I need to analyse this image to find the with of the central object (I need it in uint, grayscale or double format)
C = readmatrix('No_shift.xlsx');
D = readmatrix('5cm_Shift.xlsx');
xC = C(:,1);
yC = C(:,2);
zC = C(:,3);
xD = D(:,1);
yD = D(:,2);
zD = D(:,3);
n = 290.39;
[Xc, Yc] = meshgrid(linspace(min(-150),max(150),n), linspace(min(-150),max(150),n));
Zc = griddata(xC,yC,zC,Xc,Yc);
[Xd, Yd] = meshgrid(linspace(min(-150),max(150),n), linspace(min(-150),max(150),n));
Zd = griddata(xD,yD,zD,Xd,Yd);
figure (1) % Plot the original image C
GlobalPosZX_C = imagesc(Zc);
title('O R I G I N A L I M A G E: Unshifted')
figure (2) % Plot the shifted image 5cm
GlobalPosZX_D = imagesc(Zd);
title('S H I F T E D : 5cm Shift')

Answers (2)

dpb on 15 Aug 2023
Moved: dpb on 16 Aug 2023
C = readmatrix('No_shift.xlsx');
n = 290.39;
[Xc, Yc] = meshgrid(linspace(-150,150,n), linspace(-150,150,n));
Zc = griddata(C(:,1),C(:,2),C(:,3),Xc,Yc);
GlobalPosZX_C = imagesc(Zc);
What you mean can't further analyze it? Reference <the properties> to get access to the image object.
Of course,
ans = logical
anyway, so you can do whatever you want with the initial array directly; the visual in imagesc is really totally immaterial.
  1 Comment
Yanique on 16 Aug 2023
I need to calculate the magnitude of the shift from one image to the other and verify that a 5cm shift was done.

Sign in to comment.

Steven Lord
Steven Lord on 16 Aug 2023
I think what you want is the xcorr2 function from Signal Processing Toolbox. I think if you adapt the "Align Two Images Using Cross-Correlation" example on that documentation page to use your data instead of the sample image data and tie the values xcorr2 returns in the example to your X and Y coordinate data you could show what you're trying to show.

Community Treasure Hunt

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

Start Hunting!