macro 'Image Correlation [I]'; {Generates an XY plot indicating how well correlated two images are. It uses the z-value of a given pixel in a certain slice as the x-coordinate; z-value of the corresponding pixel in another slice as the y-coordinate. These are plotted into a new window to give a scatter plot. The percentage done is shown in the Info window.} var xmin, xmax, ymin, ymax, xscale, yscale, Percent: real; xslice, yslice, nPixels, ticks: integer; width, height, x, y, xvalue, yvalue, Pointvalue: integer; wide, high, StackID, PlotID, margin, ticksize: integer; time: real; begin if nSlices=0 then begin beep; PutMessage('This macro requires a stack.'); exit end; SaveState; InvertY(true); KillRoi; GetPicSize(wide, high); nPixels:=wide * high; Measure; StackID := PidNumber; xslice := GetNumber('Slice to plot on the x-axis:', 1); yslice := GetNumber('Slice to plot on the y-axis:', 2); width := 256; height := 256; SetNewSize(width,height); SetForeground(255); SetBackground(0); MakeNewWindow('Plot'); InvertY(true); PlotID := PicNumber; SelectPic(StackID); SetCursor('watch'); ticks := TickCount; for y := 0 to high - 1 do begin for x := 0 to wide - 1 do begin ChoosePic(StackID); ChooseSlice(xslice); xvalue:=GetPixel(x, y); {ie z-value of pixel (x,y) on one slice} ChooseSlice(yslice); yvalue:=GetPixel(x, y); {ie z-value of same pixel on other slice} ChoosePic(PlotID); Pointvalue := GetPixel(xvalue, 255 - yvalue); if PointValue < 254 then PointValue:=PointValue+1; PutPixel(xvalue, 255 - yvalue, PointValue); end; {for x...} if (y mod 10) = 0 then ShowMessage((y / high) * 100:2:0, '% done'); end; {for y...} time := (TickCount-ticks) / 60; ShowMessage(nPixels:1, ' pixels\', time:1:2, ' seconds\', nPixels/time:1:0, ' pixels/second'); SelectPic(StackID); SelectSlice(xSlice); SelectPic(PlotID); SelectAll; EnhanceContrast; ApplyLut; SelectAll; Copy; Dispose; margin := 75; ticksize := 6; SetNewSize(width + (2 * margin), height + (2 * margin)); SetForeground(255); SetBackground(0); MakeNewWindow('Correlation Plot'); SetFont('Geneva'); SetFontSize(9); InvertY(true); MakeRoi(margin, margin, 256, 256); Paste; MakeRoi(margin - 1, margin - 1, 258, 258); SetLinewidth(1); DrawBoundary; KillRoi; MoveTo(margin, margin + 255); LineTo(margin, margin + 255 + ticksize); MoveTo(margin + 50, margin + 256); LineTo(margin + 50, margin + 256 + ticksize); MoveTo(margin + 100, margin + 256); LineTo(margin + 100, margin + 256 + ticksize); MoveTo(margin +150, margin + 256); LineTo(margin + 150, margin + 256 + ticksize); MoveTo(margin + 200, margin + 256); LineTo(margin + 200, margin + 256 + ticksize); MoveTo(margin + 255, margin + 256); LineTo(margin + 255, margin + 256 + ticksize); MoveTo(margin - 1, margin + 255); LineTo(margin - ticksize, margin + 255); MoveTo(margin - 1, margin + 206); LineTo(margin - ticksize, margin + 206); MoveTo(margin -1 , margin + 156); LineTo(margin - ticksize, margin + 156); MoveTo(margin - 1, margin + 106); LineTo(margin - ticksize, margin + 106); MoveTo(margin - 1, margin + 56); LineTo(margin - ticksize, margin + 56); MoveTo(margin - 1, margin); LineTo(margin - ticksize, margin); MoveTo(margin - 25, margin); Writeln('255'); MoveTo(margin - 25, margin + 56); Writeln('200'); MoveTo(margin - 25, margin + 156); Writeln('100'); MoveTo(margin - 14, margin + 256); Writeln('0'); MoveTo(margin - 2, margin + 270); Writeln('0'); MoveTo(margin + 92, margin + 270); Writeln('100'); MoveTo(margin + 192, margin + 270); Writeln('200'); MoveTo(margin + 248, margin + 270); Writeln('255'); MoveTo(margin + 70, margin + 290); Writeln('Z-value on slice', xslice:1); MoveTo(margin - 65, margin + 100); Writeln('Z-value'); MoveTo(margin - 65, margin + 115); Writeln('on slice', yslice:1); RestoreState; end;