How to remove the black outlines when using 'image' command to display a image.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Qianqian Pan
el 7 de Jul. de 2017
Comentada: Rena Berman
el 5 de Mzo. de 2019
Hi everyone,
I wanna display an image but also want to drag and drop this image. As far as I know, if I use command 'imshow' to display the image it is not draggable. I therefore have to use command 'Image' to display a single pixel image.
To simplify my question, I use the minimum code to this problem. See below.
Figure;
axes; % to draw an axes
I = ones(1,1,3); I(:,:,1) = 255; I(:,:,2) = 255;I(:,:,3) = 0; % to create a single pixel image file (yellow of course).
image(I) % display the single pixel yellow image in the axes.
ALL THE OUTLINES AROUND THE YELLOW IMAGE ARE UNWANTED. THEREFORE,
set(gca,'xtick',[]); % remove ticks on x-axis
set(gca,'ytick',[]); % remove ticks on y-axis
It then left with the black outlines around the yellow image which is unwanted. See below.
My question is: how to remove these black outlines if I use command 'Image' to show an image which can be dragged later on?
Many thanks!
Lily
1 comentario
Respuesta aceptada
Jan
el 7 de Jul. de 2017
Editada: Jan
el 7 de Jul. de 2017
I = ones(1,1,3);
I(:,:,1) = 255; I(:,:,2) = 255;I(:,:,3) = 0;
AxesH = axes('Visible', 'off', 'NextPlot', 'add');
image(I, 'Parent', AxesH);
Setting the Visiblility to 'off', hides the ticks and the box.
5 comentarios
Jan
el 7 de Jul. de 2017
Editada: Jan
el 7 de Jul. de 2017
Hhigh-level commands lile plot and image clean up the axes before they insert the object. This resets the limits, ticks, and many other properties, as also the value of 'Visible'.
Using hold('on') sets the property 'NextPlot' of the axes from the default 'replace' to 'add', such that imgae is instructed just to add the new object and not to clean up the properties. Instead of using the hold command, I set the 'NextPlot' property manually.
Try it:
figure;
pause(1)
AxesH = axes();
title(AxesH, 'Title');
xlabel('X');
ylabel('Y');
pause(1)
set(AxesH, 'Visible', 'off');
pause(1)
image(I, 'Parent', AxesH);
get(AxesH, 'Visible') % 'on' !!!
and now insert the 'NextPlot', 'add' in the axes() command: you will see, that the properties are preserved
figure;
pause(1)
AxesH = axes('NextPlot', 'add');
title(AxesH, 'Title');
xlabel('X');
ylabel('Y');
% pause(1)
% set(AxesH, 'Visible', 'off');
pause(1)
image(I, 'Parent', AxesH);
I've omitted to disable the visibility, because otherwise you could not see, that nothing is changed... ;-)
I find axes('NextPlot', 'add') cleaner and more direct than axes(); hold('on'), but this is a question of taste.
Alternatively you can call image() at first and set the visibility or the box afterwards.
Más respuestas (1)
Image Analyst
el 7 de Jul. de 2017
Set Box to off:
ax = gca
properties(ax) % Display properties if you want to see what you can control.
ax.Box = 'off'; % Turn off the box
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!