ModifyImage should not use local wave names. It must be a global name

It is assumed to be used in a function, and
Which of the following is correct?

Wave M_image=$"wavename"

and then
1.ModifyImage /W=$S_WinName M_image cindex=CM_ColorScale
2.ModifyImage /W=$S_WinName $nameofwave(M_image) cindex=CM_ColorScale

1.ModifyImage /W=$S_WinName M_image cindex=CM_ColorScale
2.ModifyImage /W=$S_WinName $nameofwave(M_image) cindex=CM_ColorScale


The answer is 2.

Image data is passed as a string with the global wave name. Otherwise, the following error occurs...
While executing ModifyImage, the following error occurred: Expected the name of an image in the top graph.

I got stuck on this and lost a whole day of New Year's. Why is this? It's a reasonable specification considering that it is used as a command, but wouldn't it be better to accept 'M_image'? I don't remember if there is a description of this in the manual or some other document. Or has someone already pointed this out somewhere?

I guess I still have a lot to learn.

The name expected by ModifyImage is an "image name", not a wave name.

To understand this, consider these commands which display the same matrix twice in a single graph:

Make/O/N=(5,5) mat = gnoise(1)
Display/N= ImagePlot0
AppendImage/L=left1 mat
ModifyGraph freePos(left1)=0, axisEnab(left1)={0,0.45}
AppendImage/L=left2 mat
ModifyGraph freePos(left2)=0,axisEnab(left2)={0.55,1}

Now execute this to create a graph recreation macro:

DoWindow/R ImagePlot0

This creates the following recreation macro in the procedure window:

Window ImagePlot0() : Graph
    PauseUpdate; Silent 1       // building window...
    Display /W=(35,45,430,253)
    AppendImage/L=left1 mat
    ModifyImage mat ctab= {*,*,Grays,0}
    AppendImage/L=left2 mat
    ModifyImage mat#1 ctab= {*,*,Grays,0}
    ModifyGraph mirror(bottom)=0
    ModifyGraph freePos(left1)=0
    ModifyGraph freePos(left2)=0
    ModifyGraph axisEnab(left1)={0,0.45}
    ModifyGraph axisEnab(left2)={0.55,1}
EndMacro

Note the first ModifyImage command uses the image name "mat" while the second uses "mat1". ModifyImage could not use the wave name because it is the same wave and there would be no way to target the two image plots.

This is analogous to trace names. While it would be rare to use the same matrix twice in an image plot, it is less rare to use the same wave twice in a graph. Consequently Igor distinguishes between wave names and trace names, and the ModifyGraph command expects trace names. This is explained under the following help topic:

DisplayHelpTopic "Programming With Trace Names"

With traces, you can explicitly use a trace name that is different from the wave name:

Make/O/N=5 wave0=p
Display/N=Graph0 wave0/TN=trace0
AppendToGraph/W=Graph0 wave0/TN=trace1
ModifyGraph mode(trace1)=3,marker(trace1)=2,msize(trace1)=5,rgb(trace1)=(0,0,65535)

I don't think there is a way to specify an explicit image name analogous to specifying an explicit trace name.