Add custom x and y axes (not relevant to the image)

48 ビュー (過去 30 日間)
James Blackwell
James Blackwell 2019 年 4 月 25 日
Hi
I have an image with a 40x40 cm Field of View.
The image itself is a 432x432 pixel image so my workaround was to try scale the image by multiplying the values by 0.1, but it's not an ideal solution as it doesn't scale perfectly (using a scaling factor of 0.09259259259 ruins the axis) and also the axes dont start from the same zero point.
Is it possible to set a custom axes on the image to show 0-40 on the x and y axes? (instead of 40-0 on the y axis at the moment, reversing the axis currently flips the image).
conversion=0.1; % in cm/pixel
addMMx=@(x) sprintf('%1d',x*conversion);
addMMy=@(y) sprintf('%1d',y*conversion);
xticklabels(cellfun(addMMx,num2cell(xticks'),'UniformOutput',false));
yticklabels(cellfun(addMMy,num2cell(yticks'),'UniformOutput',false));
xlabel('cm')
ylabel('cm')
h = colorbar;
set(h,'YTick',[])
ylabel(h, 'Relative Temperature');

採用された回答

Rik
Rik 2019 年 4 月 25 日
The code below should help. You can specify tick labels that have nothing to do with the ticks themselves.
%start out with a clean figure
figure(1),clf(1)
%get an example image to work with
h=image;im=h.CData;im=imresize(im,10);
%create the plot itself
imshow(im),colormap('jet')
caxis([0 32])%adjust color axis to fit the image
axis on
%calculate the locations of the ticks and the appropriate labels
FOV=40;
cm_ticks=0:5:40;
px_ticks_x=linspace(0.5,size(im,1)+0.5,numel(cm_ticks));
px_ticks_y=linspace(0.5,size(im,2)+0.5,numel(cm_ticks));
ticklabels=cellfun(@(v) sprintf('%d',v),num2cell(cm_ticks),...
'UniformOutput',false);
%apply ticks and custom ticklabels
set(gca,'XTick',px_ticks_x)
set(gca,'XTickLabels',ticklabels)
set(gca,'YTick',px_ticks_y)
set(gca,'YTickLabels',ticklabels(end:-1:1))
xlabel('cm')
ylabel('cm')
h = colorbar;
set(h,'YTick',[])
ylabel(h, 'Relative Temperature');
  4 件のコメント
Rik
Rik 2021 年 4 月 16 日
@José Anchieta de Jesus Filho Have a read here and here. It will greatly improve your chances of getting an answer.
It is not immediately obvious to me how your question relates to this question. Please post it as a separate question thread. Feel free to post a link in this thread.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by