在MATLAB中向图像添加色彩图

时间:2018-08-04 16:40:36

标签: matlab image-processing colormap

这是一个相当入门的问题,但是我在SO或Mathworks帮助中找不到答案。

我想在正在加载的图像上添加一个颜色条,然后将其与创建的颜色条一起保存。

我正在寻找的结果类似于this page上的图1,除了有一个图像而不是绘图,并且彩条显示了图像中强度的范围。

页面使我认为正在运行

Public Sub auo_open()

Dim strPassword As String
strPassword = "Athens"

With Tabelle1
    .Unprotect Password:=strPassword
    .Cells.Locked = True

    On Error Resume Next
    .Range("A:D").SpecialCells(xlCellTypeBlanks).Locked = False
    On Error GoTo 0
    .Protect Password:=strPassword, UserInterfaceOnly:=True, AllowFormattingCells:=True, AllowInsertingRows:=True

End With
Exit Sub

可以解决问题,但是当我尝试将其应用于图像时会抛出错误。

所以我的问题是,如何为图像制作一个颜色条,并且一旦完成,将如何将两者连接起来保存。

我正在使用以下代码段加载图像

Public Sub Protection()
 Dim ws As Worksheet
 Dim strPassword As String
 strPassword = "Athens"


For Each ws In ThisWorkbook.Worksheets

    ws.Unprotect Password:=strPassword
    ws.Cells.Locked = True

    On Error Resume Next
    ws.Range("A:D").SpecialCells(xlCellTypeBlanks).Locked = False
    On Error GoTo 0
    ws.Protect Password:=strPassword, UserInterfaceOnly:=True, AllowFormattingCells:=True, AllowInsertingRows:=True
Next ws
End Sub

1 个答案:

答案 0 :(得分:2)

您使用的语法是colorbar(target)。根据{{​​3}}, target是:

  

“颜色条的目标,指定为具有ColorbarVisible属性的Axes对象,PolarAxes对象或图形对象”。

您要输入im的图像矩阵(target),它不是上述对象。您只需输入:

colorbar;

或者如果您想赋予轴手柄,则:

colorbar(gca);

您可以使用documentation保存结果。

saveas(gca, 'barabara_withMAP.png')