How to obtain an intensity matrix from a surface object?

3 visualizzazioni (ultimi 30 giorni)
Hi,
I've sliced a set of volumetric data (V) using the function sl = slice(V,xslice,yslice,zslice).
I end up with a surface object like the one in the image. I need to get a 2D matrix that matches in size the area of my surface and has value 0 where the surface is dark and value 1 where the surface is yellow. In practice, i need to map the position of the yellow circles by having the coordinates of every yellow pixel. Can you please help me?

Risposta accettata

Mehmed Saad
Mehmed Saad il 21 Apr 2020
This might work for your case (it is not necessary that this works for every condition)
[X,Y,Z] = meshgrid(-2:.2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = [];
yslice = [];
zslice = 1;
h= slice(X,Y,Z,V,xslice,yslice,zslice);
mat_2d = h.CData;
figure,surf(mat_2d)
  1 Commento
wals
wals il 21 Apr 2020
Thanks for your help! Unfortunately I've tried that, and for some reason I always end up with an empty array, as if CData only contained zeros.. I'm attaching the slice i get, maybe looking at it direcly helps finding a solution

Accedi per commentare.

Più risposte (1)

Ameer Hamza
Ameer Hamza il 21 Apr 2020
Modificato: Ameer Hamza il 21 Apr 2020
Try this. It extracts color value from the surface and find the center of each circle, using the functions from image processing toolbox.
load('sl.mat');
im = sl(3).CData;
im = imbinarize(im);
reg = regionprops(im);
centers = reshape([reg.Centroid], 2, [])';
x_center = centers(:,1);
y_center = centers(:,2);
figure;
imshow(im);
hold on;
plot(x_center, y_center, 'r+');

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by