matlab 显示 块 颜色,Matlab图像传奇与颜色块

我正在尝试为使用label2rgb的标签图像和自定义颜色贴图制作的彩色贴图图像制作图例.基本上我想要一个图例,显示颜色图颜色的小矩形样本以及自定义标签.

我希望能够设置标签和背景的颜色.使用imshow显示图像,显然图例对这些图形没有影响.

我已经尝试过使用colorbar来解决这个问题,如下所示,但我对它非常不满意,因为如果我调整绘图窗口的大小,一切都会被抛弃.

任何人都可以告诉我应该如何制作这种类型的图例,最好以某种方式使它浮动并在调整图形窗口大小时根据需要移动.如果这是不可能的,那么有人可以告诉我如何为彩色条的标签文本着色或给色条的边界框(包含其标签)一个背景颜色?如您所见,如果我没有手动添加背景白框,则标签将不可见.

谢谢.

label_image = zeros(768, 1024);

label_image(100:400, 500:600)=1;

label_image(500:600, 100:600)=2;

label_image(25:300, 100:400)=3;

custom_colormap = [ 0 1 0; 1 0 0; 0 0 1;];

label_image = label2rgb(label_image, custom_colormap, [0 0 0]);

% Make a white backround for the colorbar.

% Don't want to have to do this line.

label_image(25:140, 775:1010,:)=255;

% Show the image

imshow(label_image, 'InitialMagnification', 50);

% Here, I would like to be able to set colorbar label text color and/ or

% colorbar bounding box background color, or better yet, use some variant

% on the legend function to do this automatically

colormap(custom_colormap);

labels={'Both', 'Always Moving', 'Moved'};

hcb=colorbar('peer',gca,...

[0.7 0.8 0.03 0.1],...

'YTickLabel',labels,...

'XAxisLocation','bottom',...

'TickLength',[0 0],...

'Color',[1 0 1]);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值