Compare Overlaid 2D Images

Igor supports "simultaneous" viewing of overlaid images either with control of the alpha parameter of Gizmo surfaces, or as described in the manual, by adjusting the top image color scale for certain values. Here is another approach that uses a window-shade effect in an image-display graph; when the slider control is moved, it exposes the bottom image by reversibly setting the exposed top region to NaNs. A hook function adjusts the slider to match some window changes. The Graph parameters can be adjusted to your taste. Copy this procedure file in a new pxp, and then run test(5,101); setup() from the command line to show an example. I believe the Graph will update automatically to changes in the image waves as long as a wave1 duplicate, wsave, is made at the same time, as in the Test(f,Npts) example function. To be safe, run the setup() function after image-wave changes.
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function Test(f, Npts)  // make two test images for comparison
    variable f , Npts    // spatial frequency for test images; number of points
    make/O/N=(Npts, Npts) wave0
    setscale/I x, -0.5, 0.5, "" wave0
    setscale/I y, -0.5, 0.5, "" wave0
    wave0  = (cos(x*2*pi*f)*cos(y*2*pi*f))^2
    duplicate/O wave0, wave1
    MatrixOp  /O /S wave1 = 0.75*RotateCols(wave1, 3)  // alter wave1 from wave0
    duplicate/O wave1, wsave   // save a copy
end

Function setup()  // Graph the bottom (wave0) and top (wave1) images; add slider and its hook sizing function
    WAVE wave0, wave1, wsave
    variable/G Nmax = DimSize(wave0, 0) - 1 // x-dimension points for Slider max value
    variable Vmax0 = waveMax(wave0)
    variable Vmin0  = waveMin( wave0)
    variable Vmax1 = waveMax(wave1)
    variable Vmin1  = waveMin( wave1)
    variable Vmax   = max(Vmax0, Vmax1) // for common color scale ranges
    variable Vmin    = min(Vmin0, Vmin1)
    variable/G pG   //  global pixel value for slider

    DoWindow/F Graph0   // Bring graph to front
    if (V_Flag == 0)          // if not found, make new Graph0 for overlaid images with slider for transparent boundary
        PauseUpdate; Silent 1.
        Display/N=Graph0 /W=(413.25,44.75,769.5,427.25)
        AppendImage/T wave0
        AppendImage/T wave1
        ModifyGraph margin(left)=14,margin(bottom)=14,margin(top)=14,margin(right)=14,height={Plan,1,left,top}
        ModifyGraph mirror=2, nticks=3, minor=1,fSize=8, standoff=0, tkLblRot(left)=90, btLen=3,  tlOffset=-2
        SetAxis/A/R left
        ControlBar/B 35
        Slider slider0,pos={11,482},size={455,16},proc=SliderProc
        Slider slider0,limits={0,Nmax,1},variable= pG,side= 2,vert= 0,ticks= 0
        SetWindow kwTopWin,hook(MyHook)=MyWindowHook
        DoUpdate
    endif
    GetWindow  Graph0, psizeDC // gets V_left, V_right, V_top, V_bottom
    ModifyImage wave0 ctab= {Vmin,Vmax,Terrain,0}
    ModifyImage wave1 ctab= {Vmin,Vmax,Terrain,0} // common limits
    Slider slider0 limits = { 0, Nmax, 1}
    Slider slider0 pos   = { 11,  V_bottom+25}
    Slider slider0 size   = { V_right-V_left+16, 20 }
End

Function compare(n)
    variable n
   
    WAVE wave0, wave1, wsave
    wave1 = wsave  // reload full original
    if (n==0)
        return 0
    endif
    wave1[0,n][] = NaN // make left side of top image transparent
End

Function SliderProc(ctrlName,sliderValue,event) : SliderControl
    String ctrlName
    Variable sliderValue
    Variable event  // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved

    if(event %& 0x1)    // bit 0, value set
        compare(sliderValue)
    endif

    return 0
End

Function MyWindowHook(s)    //  if window resized, adjust slider to match
    STRUCT WMWinHookStruct &s
    Variable hookResult = 0
    wave wave0
    switch(s.eventCode)
        case 6: // graph resize
            GetWindow  Graph0, psizeDC
            Slider slider0 pos   = { 11,  V_bottom+25}
            Slider slider0 size  = { V_right-V_Left+16, 20 }
            break
        case 8: // graph (wave size) modified
            Slider slider0 limits = { 0,(DimSize(wave0, 0) - 1), 1}
            break
    endswitch
    return hookResult // 0 if nothing done, else 1
End

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More