How to remove the black outlines when using 'image' command to display a image.

3 views (last 30 days)
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

Accepted Answer

Jan
Jan on 7 Jul 2017
Edited: Jan on 7 Jul 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 Comments
Qianqian Pan
Qianqian Pan on 7 Jul 2017
@ Jan Simon, can I ask why it needs 'NextPlot','add' here? I'm not sure what that is for. Many thanks!
Jan
Jan on 7 Jul 2017
Edited: Jan on 7 Jul 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.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 7 Jul 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

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!