//*****************************Polyp measurements********* 10/6/94 //2 nested macros of modular construction for estimating polyp volumes from //area measures //1st macro, this one, is the control macro that sets the configuration, //data file export parameters, test measures, and control of cyclic processing //2nd macro contains code for custom DEFINE recursive function routines to //be handed over //to the last DEFINE routine that will combine these called functions to //generate measures for the image //Second macro is nested within the first //writes data to file in an excel compatible format //- - - - - - - - - - - - - - - - - - - - - - - - -1- - - - - - - -set //initial configuration //clear frame grabber and screen New( ); OpenConfiguration("C:/OPTIMAS/POLYP.CFG"); //Optimas data file for results to be written to DataFile("C:/AR/DA/9011.OPS"); //declare a character variable that codes directory path and filename of //the dos data file GLOBAL CHAR meas_file="c:/ar/da/": Prompt("Type name of data file \n (<9 symbols)","CHAR"); //Create a dos-compatible file to export the measurements to df=OpenFile(meas_file, 0x1000); CloseFile(df); //Configure screen such that coordinates refer to the whole monitor frame IntConfigData[28]=0; //Configure such that coordinates are centered in the screen IntConfigData[29]=1; Calibrate(Default_Frame28cmWide); do { GLOBAL REAL vROI[2,2]=Prompt("Type in ROI values", "REAL"); SelectROI(vROI); } while(Prompt("Press OK if parameters entered correctly or Cancel otherwise")==FALSE); //- - - - - - - - - - - - - - - - - - - - - - - - - -2- - - - - Test //measurements for analysis parameters- - - - - Macromessage("Now measure polyp area and set classification range"); //Declare character variable specifying image directory GLOBAL CHAR cDir_im=Prompt("Enter path to directory where images are stored (using forward slashes)", "CHAR"):"/"; //Declare character variable specifying image file for measurements // a concatenated character vector with cDir_im, the integer for frame # // entered at prompt and label, p.tif iN=Prompt("Enter frame number for measurements", "INTEGER"); GLOBAL CHAR cFilename=cDir_im:ToText(iN):"P.TIF"; New( ); SelectROI(vROI); OpenImage(cFilename, ROI); MotionFilter(ROI); Macromessage("Measure and record polyp width at tip"); CreateLine( ); SetExport(LnLength, 0, TRUE); Calibrate(cal901); DataCollection( ); Extract( ); SetExport(LnLength, 0, FALSE); Calibrate(Default_Frame28cmWide); ClearScreen(FALSE); Macromessage("Set threshold for this analysis"); CloseWindow("Data Collection"); Threshold( ); //Transform all foreground pixels to luminance 252, and background pixels to 0 GrayToBinary( ); // In the standard calibrated units 28cm correspond to 640 pixels. We want // to add a black line of 4 pixels on the right hand side, this is // (28.0/640)*4=0.175 in callibrated units. // (22.0/480)*4=0.1833333333 vROI=ROI + (-0.175:0.183333::0.175:-0.183333); SelectROI(vROI); //Declare a real vector representing a vertical line that runs along the //x(polyp/stolon) // boundary from top to bottom of the ROI // This one is the right edge line in calibrated units. // So now convert it to pixels and make it 4 pixels thick (to the left). // right GLOBAL REAL vLine_base[2,2]=ROI[1,0]:(ROI[0,1]*0.7 +ROI[1,1]*0.3) ::ROI[1,0]:(ROI[1,1]*0.7 +ROI[0,1]*0.3) ; GLOBAL INTEGER vPix_r[2,2]=ConvertCalibToPixels(vLine_base[])+(-4:0::0:0); // left vLine_base=ROI[0,0]:ROI[0,1]::ROI[0,0]:ROI[1,1]; GLOBAL INTEGER vPix_l[2,2]=ConvertCalibToPixels(vLine_base[])+(0:0::4:0); // top vLine_base=ROI[0,0]:ROI[0,1]::ROI[1,0]:ROI[0,1]; GLOBAL INTEGER vPix_t[2,2]=ConvertCalibToPixels(vLine_base[])+(0:0::0:2); // bottom vLine_base=ROI[0,0]:ROI[1,1]::ROI[1,0]:ROI[1,1]; GLOBAL INTEGER vPix_b[2,2]=ConvertCalibToPixels(vLine_base[])+(0:-2::0:0); //Declare a byte vector representing a vertical line of pixels that is //4 pixels wide // and the height (in pixels) from the bottom to the top of the ROI // having luminance values =0 (black) GLOBAL BYTE vBlackline[2560] = 0Y; //Place a frame of black pixels to isolate and separate the polyp from //the edge of the ROI PutPixelRect(vPix_r, vBlackline); PutPixelRect(vPix_l, vBlackline); PutPixelRect(vPix_t, vBlackline) ; PutPixelRect(vPix_b, vBlackline); InvertFilter( ); ErodeFilter( ); //set parameters for sampling of areas. In particular, delete areas //touching ROI and delete areas nested within areas AREACNVFactors=0.0 : 1.0 : -1.0 : 256.0 : 0.0 : 50.0 : 1.0 : 1.0 : -1.0; CreateArea( , FALSE, TRUE); DataCollection( ); Prompt("Measure polyp area, then press OK in this box"); CloseWindow("Data Collection"); ObjectClass( ); Prompt("Select Class 1 to add/edit and set range of object areas to analyze \n then press OK below"); CloseWindow("Object Classes"); do { //Now set parameters for which, and how many, frames will be in the //analysis Macromessage("The following parameters set the number of frames to be analyzed"); GLOBAL INTEGER iN_start_frame=Prompt("Number of start frame", "INTEGER"); GLOBAL INTEGER iN_max_frame=Prompt("Number of end frame", "INTEGER"); GLOBAL INTEGER iN_total_frames=iN_max_frame - iN_start_frame + 1; GLOBAL INTEGER iN=0; //current frame # GLOBAL INTEGER frame_no=iN; Viewbox(frame_no); } while (Prompt("Press OK if you're a happy camper or Cancel otherwise")==FALSE); Macromessage("Jim, Jim, Press OK to start measurements, if it blows hit Esc, then run"); //- - - - - - - - - - - - 3- - - Set Global variables to hand over to //nested macro routines StartTime = DOSTime( ); //pixel dimensions (cm of monitor/pixel for a 640 by 480 screen) GLOBAL REAL dx=0.04375; GLOBAL REAL dy=0.04583; //Set line sampling parameters so that luminance and segment interval are //sampled pixel by pixel LineCNVFactors[0..6]=0.0 : 1.0 : 0.0 : 1.0 : 0.0 : 2.0; GLOBAL INTEGER iN_max_width_meas=11; GLOBAL INTEGER iN_dx_step=11; GLOBAL INTEGER iN=0; GLOBAL REAL rDist[iN_max_width_meas + 4]=0; GLOBAL REAL dx_step=0; GLOBAL REAL vPoints_polyp_axis[iN_max_width_meas, 2]=0; GLOBAL REAL vSmooth_Points_polyp_axis[iN_max_width_meas+1, 2]=0; GLOBAL REAL vPolyp_box[2,2]=0; GLOBAL REAL vLine_polyp_diam[iN_max_width_meas]=0; RunMacro("c:/ar/al/scan6.mac"); ClearScreen(FALSE); ClearScreen(TRUE); DEFINE cyclicmeas ( ) { //beginning of cyclic measures iN = iN_start_frame; do { frame_no = iN; TextToScreen("Select New Frame", -5.0:-5.0, 1); New( ); SelectROI(vRoi); cFilename = cDir_im : ToText(iN) : "P.TIF"; OpenImage(cFilename, ROI); rDist[0] = (REAL) iN; ClearScreen( ); ErodeFilter( ); Polyp_axis_tracing( ); } while (++iN<=iN_max_frame); ClearScreen( ); TextToScreen("End of Measurements", -5.0:-5.0, 1); Macromessage("Elapsed seconds = ", DOSTime( ) - StartTime); Pause( ); } //end of cyclicmeas cyclicmeas( );