{from Globals.header} var Raw16Pid, Raw8Pid, RawANDPid, RawB16Pid: integer; RawHeight, RawMaskPid, RawWidth, rawDirID, rawVRefNum: integer; frameType, firstFrame, lastFrame, nextFrame, skipFrame: integer; fore, foredef, cropheight, cropwidth, maskheight: integer; maskwidth, b16Pid, i16Pid, s16Pid, m16Pid: integer; o16Pid, i8Pid, referencePid, smoothPid, markPid: integer; maskPid, mask1Pid, mask2Pid, mask3Pid, dilatePid: integer; flagPid, kernelPid, rbKerPid, xlate16uTo8P, std65535Pid: integer; std8191Pid, customLUTPid, xmax, xmin, ymax: integer; ymin, pack16Pid, packDirID, packMarkPid, packVRefNum: integer; {initialize global variables} begin requiresUser('Pixel16u',2); requiresUser('GetPutPixel',1); requiresUser('timer',1); requiresUser('utilities',1); requiresUser('markup',1); {info about the raw data} Raw16Pid := GetMemo('Raw16Pid'); Raw8Pid := GetMemo('Raw8Pid'); RawANDPid := GetMemo('RawANDPid'); RawB16Pid := GetMemo('RawB16Pid'); RawHeight := GetMemo('RawHeight'); RawMaskPid := GetMemo('RawMaskPid'); RawWidth := GetMemo('RawWidth'); rawDirID := GetMemo('rawDirID'); rawVRefNum := GetMemo('rawVRefNum'); {raw data frame numbers} frameType := GetMemo('frameType'); firstFrame := GetMemo('firstFrame'); lastFrame := GetMemo('lastFrame'); nextFrame := GetMemo('nextFrame'); skipFrame := GetMemo('skipFrame'); {mark color} fore := GetMemo('fore'); foredef := GetMemo('foredef'); {cropped image dimensions} cropheight := GetMemo('cropheight'); cropwidth := GetMemo('cropwidth'); maskheight := GetMemo('maskheight'); maskwidth := GetMemo('maskwidth'); {scratch image pidNumbers} b16Pid := GetMemo('b16Pid'); i16Pid := GetMemo('i16Pid'); s16Pid := GetMemo('s16Pid'); m16Pid := GetMemo('m16Pid'); o16Pid := GetMemo('o16Pid'); i8Pid := GetMemo('i8Pid'); referencePid := GetMemo('referencePid'); smoothPid := GetMemo('smoothPid'); markPid := GetMemo('markPid'); maskPid := GetMemo('maskPid'); mask1Pid := GetMemo('mask1Pid'); mask2Pid := GetMemo('mask2Pid'); mask3Pid := GetMemo('mask3Pid'); dilatePid := GetMemo('dilatePid'); flagPid := GetMemo('flagPid'); {kernel information} kernelPid := GetMemo('kernelPid'); rbKerPid := GetMemo('rbKerPid'); xlate16uTo8P := GetMemo('xlate16uTo8P'); std65535Pid := GetMemo('std65535Pid'); std8191Pid := GetMemo('std8191Pid'); customLUTPid := GetMemo('customLUTPid'); xmax := GetMemo('xmax'); xmin := GetMemo('xmin'); ymax := GetMemo('ymax'); ymin := GetMemo('ymin'); {packed stack info} pack16Pid := GetMemo('pack16Pid'); packDirID := GetMemo('packDirID'); packMarkPid := GetMemo('packMarkPid'); packVRefNum := GetMemo('packVRefNum'); if pidExists(GetMemo('frontPid')) then selectPic(GetMemo('frontPid')); {end from Globals.header} {options automatically selected for this macro file} SetOptions('Area,X-Y Center'); SetCounter(255); SetBackgroundColor(0); SetForeGroundColor(255); end; macro '[F5] 16 bit arithmetic'; begin SetMemo('frontPid', pidNumber); SelectWindow('16 bit arithmetic'); LoadMacros; end; macro '[F6] Adjust 16 bit LUT'; begin SetMemo('frontPid', pidNumber); SelectWindow('Adjust 16 bit LUT'); LoadMacros; end; macro '[F7] Calculate Intensity'; begin SetMemo('frontPid', pidNumber); SelectWindow('Calculate Intensity'); LoadMacros; end; macro '[F8] Create Kernels'; begin SetMemo('frontPid', pidNumber); SelectWindow('Create Kernels'); LoadMacros; end; macro '[F9] Examine Old 16 bit Stacks'; begin SetMemo('frontPid', pidNumber); SelectWindow('Examine Old 16 bit Stacks'); LoadMacros; end; macro '[F10] Examine Packed 16 bit stack'; begin SetMemo('frontPid', pidNumber); SelectWindow('Examine Packed 16 bit stack'); LoadMacros; end; macro '([F11] Examine Raw Data'; begin end; macro '[F12] Front Image Is ...'; begin SetMemo('frontPid', pidNumber); SelectWindow('Front Image Is ...'); LoadMacros; end; macro '(-'; begin end; macro 'Markup into mask image'; begin saveState; restoreState; ChoosePic(Raw8Pid); MarkupData8(picNumber); ChoosePic(Raw16Pid); MarkupData16(picNumber); ChoosePic(RawB16Pid); MarkupBkg(picNumber); ChoosePic(RawMaskPid); MarkupMarks(picNumber); MarkupShow; end; macro 'Use 65535 LUT -- 16 bits'; begin xlate16uTo8P := std65535Pid; SetMemo('xlate16uTo8P', xlate16uTo8P); end; macro 'Use 8191 LUT -- 13 bits'; begin xlate16uTo8P := std8191Pid; SetMemo('xlate16uTo8P', xlate16uTo8P); end; macro 'Use Custom LUT'; begin xlate16uTo8P := customLUTPid; SetMemo('xlate16uTo8P', xlate16uTo8P); end; macro '-)'; begin end; procedure autoDispose(p); begin if pidExists(p) then begin choosePic(p); dispose; end; end; procedure CheckFrameType; begin SetOptions('Area,X-Y Center'); SetCounter(255); if firstFrame < 1 then begin firstFrame := 1; setMemo('firstFrame',firstFrame); end; if firstFrame > 255 then begin firstFrame := 255; setMemo('firstFrame',firstFrame); end; if lastFrame < firstFrame then begin lastFrame := firstFrame; setMemo('lastFrame',lastFrame); end; if lastFrame > 255 then begin lastFrame := 255; setMemo('lastFrame',lastFrame); end; if nextFrame < firstFrame then begin nextFrame := firstFrame; SetMemo('nextFrame', nextFrame); end; if nextFrame > lastFrame then begin nextFrame := lastFrame; SetMemo('nextFrame', nextFrame); end; if frameType <> 1 then begin if frameType <> 2 then begin if frameType <> 3 then begin PutMessage('please specify frame type'); exit; end; end; end; end; procedure OpenOneFrame; begin {Uses ImportOnto(vRefNum,DirID,'name')} if nextFrame < firstFrame then begin nextFrame := firstFrame; SetMemo('nextFrame', nextFrame); end; if nextFrame > lastFrame then begin nextFrame := lastFrame; SetMemo('nextFrame', nextFrame); end; if frameType = 1 then begin SetCustom(RawWidth*2,RawHeight,490+24*1024); {486} SetImport('custom,8-bits'); {Import('Frame ',nextFrame:4);} choosePic(Raw16Pid); KillRoi; ImportOnto(rawVRefNum,rawDirID,concatZF('Frame ',nextFrame:4)); end; if frameType = 2 then begin SetCustom(RawWidth*2,RawHeight,0); SetImport('custom,8-bits'); {Import('Frame ',nextFrame:4);} choosePic(Raw16Pid); KillRoi; ImportOnto(rawVRefNum,rawDirID,concatZF('Frame ',nextFrame:4)); end; if frameType = 3 then begin SetDefFolder(rawVRefNum,rawDirID); Open('Frame ',nextFrame:4); SelectAll; Copy; Dispose; choosePic(Raw16Pid); KillRoi; Paste; end; Cnvrt16uto8(Raw16Pid,xlate16uTo8P, Raw8Pid); showMessage('Frame ',nextFrame); SelectPic(Raw8Pid); end; procedure setupRegister; begin ChoosePic(RawMaskPid); SelectAll; Copy; ChoosePic(RawANDPid); SelectAll; Paste; ChoosePic(Raw8Pid); SelectAll; Copy; KillRoi; ShowPasteControl; SelectPic(RawANDPid); RestoreRoi; if rX[nextFrame] <> 65536 then MoveRoi(rX[nextFrame],rY[nextFrame]); end; procedure SetupImages; begin autoDispose(Raw16Pid); autoDispose(Raw8Pid); autoDispose(RawANDPid); autoDispose(RawB16Pid); autoDispose(RawMaskPid); SaveState; SetDefFolder(rawVRefNum,rawDirID); if firstFrame < 1 then firstFrame := 1; if lastFrame < firstFrame then lastFrame := 255; firstFrame := GetNumber('first frame to examine',firstFrame); SetMemo('firstFrame', firstFrame); lastFrame := GetNumber('last frame to examine',lastFrame); SetMemo('lastFrame', lastFrame); nextFrame := firstFrame; SetMemo('nextFrame', nextFrame); if frameType = 1 then begin RawHeight := 486;{ 512;} SetMemo('RawHeight', RawHeight); RawWidth := 512; SetMemo('RawWidth', RawWidth); end; if frameType = 2 then begin SetCustom(32,32,0); SetImport('custom,8-bits'); Import('Frame 0000'); RawWidth := GetPixel(0,0) * 256 + GetPixel(1,0); SetMemo('RawWidth', RawWidth); RawHeight := GetPixel(2,0) * 256 + GetPixel(3,0); SetMemo('RawHeight', RawHeight); SetCustom(RawWidth*2,RawHeight,0); Dispose; end; if frameType = 3 then begin Open('Frame ',nextFrame:4); GetPicSize(RawWidth,RawHeight); Dispose; RawWidth := RawWidth div 2; SetMemo('RawWidth', RawWidth); end; if not pidExists(xlate16uTo8P) then begin SetNewSize(256,256); SetBackgroundColor(0); MakeNewWindow('16 bit to 8 bit look up table'); xlate16uTo8P := pidNumber; SetMemo('xlate16uTo8P', xlate16uTo8P); linLUT16uto8(xlate16uTo8P, 0, 65535, 0, 255); end; SetNewSize(RawWidth,RawHeight); MakeNewWindow('Raw Mask image'); RawMaskPid := pidNumber; SetMemo('RawMaskPid', RawMaskPid); SetNewSize(RawWidth,RawHeight); MakeNewWindow('Raw Preview image'); RawANDPid := pidNumber; SetMemo('RawANDPid', RawANDPid); SetNewSize(RawWidth*2,RawHeight); MakeNewWindow('Raw 16 bit image'); Raw16Pid := pidNumber; SetMemo('Raw16Pid', Raw16Pid); SetNewSize(RawWidth*2,RawHeight); MakeNewWindow('Raw 16 bit background'); RawB16Pid := pidNumber; SetMemo('RawB16Pid', RawB16Pid); SetNewSize(RawWidth,RawHeight); MakeNewWindow('Raw 8 bit image'); Raw8Pid := pidNumber; SetMemo('Raw8Pid', Raw8Pid); RestoreState; CheckFrameType; OpenOneFrame; end; macro 'Dispose Raw Data windows'; begin autoDispose(Raw16Pid); autoDispose(Raw8Pid); autoDispose(RawANDPid); autoDispose(RawB16Pid); autoDispose(RawMaskPid); frameType := 0; end; macro '(-'; begin end; {frameType 1 = BioVision, 2 = Image VDM, 3 = Image TIFF 16} macro '[1] Select folder containing frame data'; begin GetDefFolder(rawVRefNum,rawDirID); SetMemo('rawVRefNum', rawVRefNum); SetMemo('rawDirID', rawDirID); end; macro '[2] Examine 16 bit frames from BioVision'; begin frameType := 1; SetMemo('frameType', frameType); SetupImages; end; macro '[3] Examine 16 bit frames from Image VDM'; begin frameType := 2; SetMemo('frameType', frameType); SetupImages; end; macro '[4] Examine 16 bit frames saved as 8 bit TIFF'; begin frameType := 3; SetMemo('frameType', frameType); SetupImages; end; macro '[5] Create Cropped Image Buffers'; var left,top,roiWidth,roiHeight: integer; picWidth, picHeight: integer; kx,ky,kw,kh: integer; kmin, kdelta, knum, koverlap: integer; begin if pidNumber <> RawMaskPid then begin ChoosePic(RawMaskPid); KillRoi; end; autoDispose(maskPid); autoDispose(markPid); autoDispose(i8Pid); autoDispose(mask1Pid); autoDispose(mask2Pid); autoDispose(mask3Pid); autoDispose(dilatePid); autoDispose(flagPid); autoDispose(i16Pid); autoDispose(b16Pid); autoDispose(o16Pid); autoDispose(s16Pid); autoDispose(m16Pid); SelectPic(RawMaskPid); GetRoi(left,top,roiWidth,roiHeight); GetPicSize(picWidth, picHeight); if roiWidth = 0 then begin PutMessage('Select the mask with wand tool'); Exit; end; if odd(roiWidth) then roiWidth := roiWidth + 1; if roiWidth + left > picWidth then left := left - 1; ChoosePic(kernelPid); kmin := getPixel(0, 0); kdelta := getPixel(1, 0); knum := getPixel(2, 0); koverlap := getPixel(3, 0); kx := kmin + kdelta * (knum - 1); ky := kmin + kdelta * (knum - 1); kw := kx * 2 + 1; kh := ky * 2 + 1; cropWidth := roiWidth; SetMemo('cropWidth',cropWidth); maskWidth := cropWidth + kw - 1; SetMemo('maskWidth',maskWidth); cropHeight := roiHeight; SetMemo('cropHeight',cropHeight); maskHeight := cropHeight + kh - 1; SetMemo('maskHeight',maskHeight); ChoosePic(RawMaskPid); MakeRoi(left,top,roiWidth,roiHeight); Copy; SaveState; SetNewSize(cropWidth, cropHeight); MakeNewWindow('cropped mask image'); Paste; maskPid := pidNumber; SetMemo('maskPid', maskPid); SetNewSize(cropWidth, cropHeight); MakeNewWindow('mark'); Paste; markPid := pidNumber; SetMemo('markPid', markPid); SetNewSize(cropWidth, cropHeight); MakeNewWindow('8 bit image'); i8Pid := pidNumber; SetMemo('i8Pid', i8Pid); SetNewSize(maskWidth, maskHeight); MakeNewWindow('mask 1'); mask1Pid := pidNumber; SetMemo('mask1Pid', mask1Pid); SetNewSize(maskWidth, maskHeight); MakeNewWindow('mask 2'); mask2Pid := pidNumber; SetMemo('mask2Pid', mask2Pid); SetNewSize(maskWidth, maskHeight); MakeNewWindow('mask 3'); mask3Pid := pidNumber; SetMemo('mask3Pid', mask3Pid); SetNewSize(maskWidth, maskHeight); MakeNewWindow('dilate'); dilatePid := pidNumber; SetMemo('dilatePid', dilatePid); SetNewSize(cropWidth, cropHeight); MakeNewWindow('flag'); flagPid := pidNumber; SetMemo('flagPid', flagPid); SetNewSize(2 * cropWidth, cropHeight); MakeNewWindow('16 bit image'); i16Pid := pidNumber; SetMemo('i16Pid', i16Pid); SetNewSize(2 * cropWidth, cropHeight); MakeNewWindow('background'); b16Pid := pidNumber; SetMemo('b16Pid', b16Pid); SetNewSize(2 * cropWidth, cropHeight); MakeNewWindow('output'); o16Pid := pidNumber; SetMemo('o16Pid', o16Pid); SetNewSize(2 * cropWidth, cropHeight); MakeNewWindow('smoothed'); s16Pid := pidNumber; SetMemo('s16Pid', s16Pid); SetNewSize(2 * cropWidth, cropHeight); MakeNewWindow('morph'); m16Pid := pidNumber; SetMemo('m16Pid', m16Pid); RestoreState; end; macro '[6] create packed stacks'; var i, n: integer; width, height: integer; begin autoDispose(pack16Pid); autoDispose(packMarkPid); SelectPic(RawMaskPid); KillRoi; GetPicSize(width, height); Measure; n := width * height - histogram[0]; width := round(Sqrt(n)+1); if width < 32 then width := 32; height := trunc(n div width + 1); SaveState; SetNewSize(width * 2, height); MakeNewStack('packed 16 bit stack'); pack16Pid := pidNumber; SetMemo('pack16Pid', pack16Pid); SetNewSize(width, height); MakeNewStack('packed mark stack'); packMarkPid := pidNumber; SetMemo('packMarkPid', packMarkPid); RestoreState; i := 0; for nextFrame := firstFrame to lastFrame do begin if rArea[nextFrame] <> 0 then begin i := i + 1; rArea[nextFrame] := i; SetMemo('nextFrame', nextFrame); OpenOneFrame; choosePic(pack16Pid); killRoi; if i > nSlices then addSlice; chooseSlice(i); choosePic(packMarkPid); killRoi; if i > nSlices then addSlice; chooseSlice(i); if rX[nextFrame] <> 65536 then begin choosePic(Raw16Pid); SelectAll; Copy; Clear; MoveRoi(rX[nextFrame] * 2,rY[nextFrame]); Paste; KillRoi; end; SqzMask16u(Raw16Pid, RawMaskPid, pack16Pid); end; end; end; macro '[7] Select folder and save packed stacks'; begin GetDefFolder(packVRefNum,packDirID); SetMemo('packVRefNum', packVRefNum); SetMemo('packDirID', packDirID); SelectPic(maskPid); KillRoi; SaveAs('Mask Image'); SelectPic(pack16Pid); SaveAs('packed 16 bit stack'); SelectPic(packMarkPid); SaveAs('packed mark stack'); end; macro '-)'; begin end; macro 'Set first and last frame numbers'; begin firstFrame := GetNumber('first frame to examine',firstFrame); SetMemo('firstFrame', firstFrame); lastFrame := GetNumber('last frame to examine',lastFrame); SetMemo('lastFrame', lastFrame); end; macro '[n]Next selected frame'; begin nextFrame := nextFrame + 1; CheckFrameType; while (nextFrame < lastFrame) and (rArea[nextFrame] = 0) do nextFrame := nextFrame + 1; while (nextFrame > firstFrame) and (rArea[nextFrame] = 0) do nextFrame := nextFrame - 1; if rArea[nextFrame] = 0 then beep; SetMemo('nextFrame', nextFrame); OpenOneFrame; SetupRegister; end; macro '[b]Previous selected frame'; begin nextFrame := nextFrame - 1; CheckFrameType; while (nextFrame > firstFrame) and (rArea[nextFrame] = 0) do nextFrame := nextFrame - 1; while (nextFrame < lastFrame) and (rArea[nextFrame] = 0) do nextFrame := nextFrame + 1; if rArea[nextFrame] = 0 then beep; SetMemo('nextFrame', nextFrame); OpenOneFrame; SetupRegister; end; macro '[f]Next frame'; begin nextFrame := nextFrame + skipFrame + 1; SetMemo('nextFrame', nextFrame); CheckFrameType; OpenOneFrame; SetupRegister; end; macro '[d]Previous frame'; begin nextFrame := nextFrame - skipFrame - 1; SetMemo('nextFrame', nextFrame); CheckFrameType; OpenOneFrame; SetupRegister; end; macro '[s]Specific frame'; begin nextFrame := GetNumber('frame number to display',nextFrame); SetMemo('nextFrame', nextFrame); CheckFrameType; OpenOneFrame; SetupRegister; end; macro 'Make 32 bit integration of all images'; var raw32Pid: integer; begin CheckFrameType; nextFrame := firstFrame; SaveState; SetNewSize(RawWidth*4, RawHeight); MakeNewWindow('Raw 32 bit integration'); RestoreState; raw32Pid := pidNumber; repeat OpenOneFrame; choosePic(raw16Pid); killRoi; choosePic(raw32Pid); killRoi; Add16uTo32s(raw16Pid,raw32Pid,raw32Pid); nextFrame := nextFrame + 1; SetMemo('nextFrame', nextFrame); until nextFrame > lastFrame; end; macro 'Show min max of front 32 bit image'; var min, max: integer; begin minMax32s(pidNumber,min,max); ShowMessage('min = ', min, ' max = ',max); end; macro 'Convert front 32 bit image to 16 bits'; var i, j, x, y: integer; inPid, outPid: integer; width, height: integer; min, max: integer; offset, divisor: integer; begin RequiresUser('pixel16u', 1); inPid := pidNumber; GetPicSize(width, height); SaveState; SetNewSize(width div 2, height); MakeNewWindow('16 bit image from ', inPid : 0); outPid := pidNumber; RestoreState; MakeRoi(0,0,width div 2, height); ChoosePic(inPid); MakeRoi(0,0,width, height); minMax32s(inPid,min,max); min := 0; {ratio doesn't work if offset is not zero} offset := min; divisor := (max - min) / 65536; if divisor < 1 then divisor := 1; ShowMessage('min = ', min, ' max = ',max, ' offset = ',offset, ' divisor = ',divisor); Cnvrt32sto16u(inPid, outPid, offset, divisor); end; procedure smoothArbitrary; var kx, ky, kw, kh: integer; width, height, wpix, hpix: integer; x16Pid, sm16Pid: integer; flagPidx, mask1Pidx: integer; begin if not pidExists(smoothPid) then begin PutMessage('Please run macro "Front image is smoothing kernel"'); Exit; end; SetBackgroundColor(0); SaveState; x16Pid := pidNumber; GetPicSize(width, height); wpix := width div 2; hpix := height; ChoosePic(smoothPid); kx := getPixel(0, 0); ky := getPixel(1, 0); kw := getPixel(2, 0); kh := getPixel(3, 0); MakeRoi(0, 1, kw * 4, kh); SetNewSize(wpix,hpix); MakeNewWindow('deleteme Flag'); flagPidx := pidNumber; ChoosePic(flagPidx); SelectAll; Clear; KillRoi; SetNewSize(wpix + kw - 1,hpix + kh - 1); MakeNewWindow('deleteme Mask1'); mask1Pidx := pidNumber; SetNewSize(wpix*2, hpix); ChoosePic(x16Pid); MakeNewWindow(getPicName,' sm ',kw:0,' x ',kh:0); sm16Pid := PidNumber; RestoreState; ChoosePic(mask1Pidx); MakeRoi(kx, ky, wpix, hpix); Clear; SetForegroundColor(255); MakeRoi(0, 0, kx, hpix + kh); Fill; MakeRoi(kx + wpix, 0, kw - kx - 1, hpix + kh) Fill; MakeRoi(kx, 0, wpix, ky); Fill; MakeRoi(kx, ky + hpix, wpix, kh - ky - 1); Fill; {Mask image must have an ROI same size as image and} {with borders matching kernel, thus:} MakeRoi(kx, ky, wpix, hpix); ChoosePic(flagPidx); MakeRoi(0,0,wpix,hpix); {in case wpix is odd, actual width is even} Convolve16u(flagPidx, x16Pid, smoothPid, kx, ky, mask1Pidx, sm16Pid); ChoosePic(flagPidx); Dispose; ChoosePic(mask1Pidx); Dispose; SelectPic(sm16Pid); end; macro 'median filter front 16 bit image to new image'; var inPid, outPid: integer; width, height: integer; begin inPid := pidNumber; killRoi; duplicate(GetPicName,' rn'); outPid := pidNumber; selectpic(inPid); getpicsize(width,height); makeRoi(2,1,width-4,height-2); selectpic(outPid); makeRoi(2,1,width-4,height-2); median16u(inPid,outPid); selectPic(inPid); killRoi; selectPic(outPid); killRoi; end; procedure rn2ms8sm; var inPid, outPid: integer; width, height, i: integer; begin killRoi; duplicate(GetPicName,' msrep'); outPid := pidNumber; duplicate('delete me'); inPid := pidNumber; i := 4{getNumber('repeat div 2',2)}; selectpic(inPid); getpicsize(width,height); makeRoi(2,1,width-4,height-2); selectpic(outPid); makeRoi(2,1,width-4,height-2); median16u(inPid,outPid); median16u(outPid,inPid); while (i > 0) do begin; minspat16u(inPid,outPid); minspat16u(outPid,inPid); i := i - 1; end; choosePic(inPid); dispose; selectPic(outPid); killRoi; SmoothArbitrary; inPid := pidNumber; choosePic(outPid); dispose; selectPic(inPid); end; macro 'Make 32 bit integration of all bkgs'; var bkg32Pid, bkg16Pid: integer; begin CheckFrameType; nextFrame := firstFrame; SaveState; SetNewSize(RawWidth*4, RawHeight); MakeNewWindow('Bkg 32 bit integration'); RestoreState; bkg32Pid := pidNumber; repeat OpenOneFrame; choosePic(raw16Pid); killRoi; rn2ms8sm; bkg16Pid := pidNumber; choosePic(bkg16Pid); killRoi; choosePic(bkg32Pid); killRoi; Add16uTo32s(bkg16Pid,bkg32Pid,bkg32Pid); choosePic(bkg16Pid); dispose; nextFrame := nextFrame + 1; SetMemo('nextFrame', nextFrame); until nextFrame > lastFrame; end; macro 'set skip count'; begin skipFrame := GetNumber('Frames to skip between slices',skipFrame); SetMemo('skipFrame', skipFrame); end; macro 'movie of ratio of all raw images by reference 16 bit image'; var inPid: integer; coef: integer; outPid: integer; begin coef := round(getNumber('integer coefficient',32768)); CheckFrameType; nextFrame := firstFrame; SaveState; SetNewSize(RawWidth, RawHeight); MakeNewWindow('8 bit Ratio'); outPid := pidNumber; RestoreState; while not button do begin OpenOneFrame; choosePic(raw16Pid); killRoi; ratio16u(raw16Pid, referencePid, raw16Pid,coef); choosePic(outPid); MakeRoi(0,0,RawWidth, RawHeight); Cnvrt16uto8(raw16Pid, xlate16uTo8P, outPid); SelectPic(outPid); nextFrame := nextFrame + skipFrame + 1; if nextFrame > lastFrame then nextFrame := firstFrame; SetMemo('nextFrame', nextFrame); end; end; macro 'Ratio of all images to stack'; var coef: integer; stkPid, bkg16Pid, i: integer; begin coef := round(getNumber('integer coefficient',32768)); CheckFrameType; nextFrame := firstFrame; SaveState; SetNewSize(RawWidth*2, RawHeight); MakeNewStack('flattened stack'); RestoreState; stkPid := pidNumber; repeat OpenOneFrame; choosePic(raw16Pid); killRoi; rn2ms8sm; bkg16Pid := pidNumber; i := nextFrame + 90; if i > lastFrame then i := lastFrame; repeat OpenOneFrame; choosePic(bkg16Pid); killRoi; choosePic(raw16Pid); killRoi; choosePic(stkPid); chooseSlice(nSlices); if nextFrame <> firstFrame then addSlice; chooseSlice(nSlices); killRoi; ratio16u(raw16Pid, bkg16Pid, stkPid,coef); nextFrame := nextFrame + 1; until nextFrame > i; SetMemo('nextFrame', nextFrame); choosePic(bkg16Pid); dispose; until nextFrame > lastFrame; end; macro 'Ratio of all images by reference image to stack'; var coef: integer; stkPid, i: integer; begin coef := round(getNumber('integer coefficient',32768)); CheckFrameType; nextFrame := firstFrame; SaveState; SetNewSize(RawWidth*2, RawHeight); MakeNewStack('flattened stack'); RestoreState; stkPid := pidNumber; repeat OpenOneFrame; choosePic(referencePid); killRoi; choosePic(raw16Pid); killRoi; choosePic(stkPid); chooseSlice(nSlices); if nextFrame <> firstFrame then addSlice; chooseSlice(nSlices); killRoi; ratio16u(raw16Pid, referencePid, stkPid,coef); nextFrame := nextFrame + 1; SetMemo('nextFrame', nextFrame); until nextFrame > lastFrame; end; macro 'front 16 bit image is reference image'; begin referencePid := pidNumber; SetMemo('referencePid', referencePid); end; macro '8 bit stack of ratio of all raw images by reference 16 bit image'; var inPid: integer; coef: integer; outPid: integer; i: integer; mean, sigma: real; begin xlate16uTo8P := std65535Pid; coef := round(getNumber('integer coefficient',32768)); CheckFrameType; SaveState; SetNewSize(RawWidth, RawHeight); MakeNewStack('8 bit Ratio'); outPid := pidNumber; RestoreState; nextFrame := firstFrame; i := 1; while nextFrame <= lastFrame do begin ResetCounter; OpenOneFrame; choosePic(raw16Pid); killRoi; ratio16u(raw16Pid, referencePid, raw16Pid,coef); choosePic(outPid); if i > nSlices then addSlice; chooseSlice(i); MakeRoi(0,0,RawWidth, RawHeight); Cnvrt16uto8(raw16Pid, std65535Pid, outPid); measure; mean := rMean[1] / 256 * 65536 + 0; sigma := rStdDev[1] / 256 * 65536; xmin := mean - 2*sigma; xmax := mean + 4*sigma; linLUT16uto8(customLUTPid, xmin, xmax, 1, 254); Cnvrt16uto8(raw16Pid, customLUTPid, outPid); SelectPic(outPid); SelectSlice(i); nextFrame := nextFrame + 1; i := i + 1; end; end; macro 'movie with histogram of front stack'; begin while not button do begin if sliceNumber = nSlices then selectslice(1) else selectslice(sliceNumber + 1); ShowHistogram; end; end; macro 'process front stack'; var lower, upper: integer; begin selectSlice(1); getThresholds(lower,upper); while true do begin setThreshold(lower); makeBinary; reduceNoise; if sliceNumber = nSlices then exit; selectSlice(sliceNumber + 1); end; end; macro 'make binary front stack'; begin selectSlice(1); while true do begin changeValues(1,255,255); if sliceNumber = nSlices then exit; selectSlice(sliceNumber + 1); end; end; macro 'integrate front stack'; var stkPid, sumPid: integer; width, height: integer; begin stkPid := pidNumber; selectSlice(1); SaveState; GetPicSize(width,height); SetNewSize(width,height); MakeNewWindow('sum'); sumPid := pidNumber; RestoreState; while true do begin selectPic(stkPid); changeValues(1,255,1); selectAll; copy; selectPic(sumPid); paste; Add; selectPic(stkPid); if sliceNumber = nSlices then exit; selectSlice(sliceNumber + 1); end; end; macro 'time average front stack'; var i, j, k, n: integer; begin n := nSlices; for i := 1 to n do begin selectSlice(i); changeValues(1,255,1); selectAll; copy; j := i - 10; if j < 1 then j := 1; for k := j to i-1 do begin chooseSlice(k); paste; Add; end; end; end;