簡體   English   中英

在MATLAB中將圖像繪制為軸標簽

[英]Plot images as axis labels in MATLAB

我正在使用imagesc命令在MATLAB中繪制7x7像素的``圖像'':

imagesc(conf_matrix, [0 1]);

這代表了七個不同對象之間的混淆矩陣 我有七個對象的縮略圖,我想用作軸刻度標簽。 是否有捷徑可尋?

我不知道一個簡單的方法。 確定標簽的軸屬性XtickLabel只能是字符串。

如果您想要一種不太容易的方法,則可以本着以下不完整(就不完整解決方案而言)代碼的精神進行操作,創建一個標簽:

h = imagesc(rand(7,7));
axh = gca;
figh = gcf;
xticks = get(gca,'xtick');
yticks = get(gca,'ytick');
set(gca,'XTickLabel','');
set(gca,'YTickLabel','');
pos = get(axh,'position'); % position of current axes in parent figure

pic = imread('coins.png');
x = pos(1);
y = pos(2);
dlta = (pos(3)-pos(1)) / length(xticks); % square size in units of parant figure

% create image label
lblAx = axes('parent',figh,'position',[x+dlta/4,y-dlta/2,dlta/2,dlta/2]);
imagesc(pic,'parent',lblAx)
axis(lblAx,'off')

一個問題是標簽將具有與原始圖像相同的顏色圖。

@Itmar Katz提供了非常接近我想要做的解決方案,我將其標記為“已接受”。 同時,我使用子圖制作了這個骯臟的解決方案,為了完整起見,在此給出了子圖。 但是,它僅適用於特定大小的輸入矩陣,並且僅在圖形為正方形時才能很好地顯示。

conf_mat = randn(5);
A = imread('peppers.png');
tick_images = {A, A, A, A, A};

n = length(conf_mat) + 1;

% plotting axis labels at left and top
for i = 1:(n-1)
    subplot(n, n, i + 1); 
    imshow(tick_images{i});
    subplot(n, n, i * n + 1);
    imshow(tick_images{i});
end

% generating logical array for where the confusion matrix should be
idx = 1:(n*n);
idx(1:n) = 0;
idx(mod(idx, n)==1) = 0;

% plotting the confusion matrix
subplot(n, n, find(idx~=0));
imshow(conf_mat);
axis image
colormap(gray)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM