Line/FreeDrawROI is not visible in axis w/ Point Cloud

Hi everyone,
I have a 3D point cloud in a Matlab App Figure. I want the user to be able to draw around an area of interest and for this to be isolated/zoomed or something like that. The problem is that if the axes are empty, the ROI works. If the PC is plotted within it, then the ROI UI appears (crosshairs) and I can draw one, but it won't show.
Testing this out in a normal script, it appears that the same issue occurs. With the same code, a couple of times I tried the ROI appeared to behave properly and show in the 3D space, while many other times I reran the same code, the ROI just never appears. I was also trying to figure out whether it was a UISTACKing issue but it isn't. The ROI object is created and placed in front, but all of its properties appear empty.
Could this be a bug? I have tested this in 2022a and 2023a, same issue.
clear
clc
% Generate random 3D point cloud data
numPoints = 10;
x = rand(numPoints, 1);
y = rand(numPoints, 1);
z = rand(numPoints, 1);
% Plot the point cloud
scatter3(x, y, z, 'filled');
xlabel('X');
ylabel('Y');
zlabel('Z');
axis equal;
grid on;
% Create a freehand ROI
Line = drawline(gca);

Réponses (1)

DGM
DGM le 28 Mai 2023
Modifié(e) : DGM le 28 Mai 2023
I haven't checked the documentation, but I seem to recall that the images.roi tools need an image object in the given axes. It's the extent and resolution of the image object that defines the size of the generated mask and the relative position of the drawn object in the mask.
% Generate random 3D point cloud data
numPoints = 10;
x = rand(numPoints, 1);
y = rand(numPoints, 1);
z = rand(numPoints, 1);
% Plot the point cloud
scatter3(x, y, z, 'filled');
xlabel('X');
ylabel('Y');
zlabel('Z');
axis equal;
grid on;
hold on;
% put a dummy image in the xy plane
% some given number of pixels stretched over the axes area
hi = image(xlim,ylim,[100 100]);
hi.AlphaData = 0; % with zero opacity
% Create a freehand ROI
roi = drawline(gca);
That will allow you to use drawline(), although you're still only going to be working in the xy plane. Also, setting alpha may tend to make the ui very laggy if you're using software rendering. Again, setting the visibility property of the image object will also disable the ROI object.

4 commentaires

Dennis Premoli
Dennis Premoli le 28 Mai 2023
Modifié(e) : Dennis Premoli le 28 Mai 2023
What's confusing is that the ROI DID show for a couple of times I tried this. Then it stopped. Futhermore, I have another plot (2d graph) which happily accepts a line ROI, so I don't think they're image dependant.
DGM
DGM le 28 Mai 2023
Modifié(e) : DGM le 28 Mai 2023
In R2019b, I can't get drawline() to work in 2D without an image object in the axes, though I wouldn't be surprised that something like that might randomly half-work. Using the older imline() does work (sort of), but the moment you call the createMask method, it'll throw an error because there's no image to use as a spatial reference. I'd dig deeper, but images.roi.Line seems to be in p-code.
Here's a simple example where this works realiably in a 2D graph in 2022a and 2023a.
Strange. That does seem to work, but using scatter3() with view(2) doesn't. Either way, it will still error if you try to use createMask.

Connectez-vous pour commenter.

Produits

Version

R2023a

Commenté :

DGM
le 28 Mai 2023

Community Treasure Hunt

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

Start Hunting!

Translated by