How to remove the black outlines when using 'image' command to display a image.
5 ビュー (過去 30 日間)
古いコメントを表示
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
採用された回答
Jan
2017 年 7 月 7 日
編集済み: Jan
2017 年 7 月 7 日
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 件のコメント
Jan
2017 年 7 月 7 日
編集済み: Jan
2017 年 7 月 7 日
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.
その他の回答 (1 件)
Image Analyst
2017 年 7 月 7 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!