////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // "Standard Feature Output" version 0.17 March 2012 // Developed by Jarkko Ylanko at McMaster Biophotonics Facility 2009-2010 // Additional MBF procedures developed by Tony J Collins and Sean Cianflone at McMaster Biophotonics Facility 2008-2009 // Report questions, bugs and concerns to info@macbiophotonics.ca ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 1. START ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 1.1 - USER INPUTS input(IN_mode, "Segmentation adjustment", "MBF_FeatureExtraction mode selection", "s", "Select analysis mode. Optimize object detection in 'Segmentation adjustment', analyze image data in 'Feature extraction', or review classification results in 'Image gallery' (only available after image data analyzed in MBF_Classify). Possible values: Segmentation adjustment, Feature extraction, Image Display. Default: Segmentation adjustment.", 0.5) input(IN_ImageONOFF, 0, "Show object reference images in Player Window", "y", "Show object borders from segmentation procedures in Player window during feature extraction. Default: off.", 4) // if one would like to see the object_detection procedure progress in the Player (note: this will display object borders as determined by nuclei_- and cytoplasm_detection prior to any object filtering coded below) input(IN_fov, 0, "Select field of view for analysis", "i", "Field of view to analyze (1...total field count); if 0, all fields will be analyzed. Default: All Fields (0).", 5) // indicate field of interest input(IN_Stencil, "All", "Select object masks for analysis", "s", "Object stencils to use for analysis below. Possible values: All, Nucleus and Cytoplasm, Nucleus, Cytoplasm, Cell. Default: All", 6) input(IN_remove, "body", "Stencil for border object removal", "s", "For removal of cells not completely captured in image. Objects will be removed from further analysis if this stencil is touching the image border. Possible values: Body, Centers, Not used. Default: Body.", 6.1) input(IN_Ch1, 0, "Reference channel for nuclei detection: Nuclei Detection", "i", "Indicate channel corresponding to object reference image according to slice order of multi-channel image file. When set to zero, the reference will be set to the channel presumed to contain far red signal in Opera Camera 3, if present, or else the first channel in the series. By convention, the reference channel will be reported as 'IM_1' (image) or 'Ch1' (channel) in the output data, and additional '#' channels as 'IM_#' or 'Ch#'. Default: 0.", 7) input(IN_RGBCh1, "Not used", "RGB reference channel: Nuclei Detection", "s", "Indicate RGB channel corresponding to object reference image. By convention, the reference channel will be reported as 'Image 1' or 'Channel 1' in the output below. Possible values: Red, Green, Blue, Not used. Default: Not used.",8) input(IN_cyto, 1, "Cytoplasm detection: Cytoplasm detection", "y", "Segmentation of cytoplasm. Detection parameter adjustments below. Default: on.", 9) // toggle for cyto detection input(IN_CytoRef, 1, "Cytoplasm reference image: Cytoplasm detection", "i", "Indicate channel corresponding to cytoplasm reference image, relative to nuclear reference image specified by convention as 'IM_1' or 'Ch1' above. Value '#' selects the #th image in the multi-channel as cytoplasm reference. Default: 1, use nuclear reference image.", 9.1) input(IN_Cont, 0, "Cell contrast filter: Cytoplasm detection", "i", "Use this to remove incorrectly segmented cells as defined by poor contrast. Higher values will lead to few cells while lower values will include more cells. Adjust by illustration. Default: 0 Keep al cells that are segmented", 9.2) input(IN_multinuc, "0", "Multinuclei detection: Nuclei Detection 2", "y", "Perform second nucleus detection procedure within cell borders to identify cells with multiple nuclei. Segmentation performed on same reference image as above nucleus detection. Requires cytoplasm detection procedure to predefine whole cell borders. Detection parameters below are independent of parameters defined for initial nuclei detection procedure above, and vice versa. Adjust by illustration Nuclei2.", 9.3) input(IN_spots, 0, "Small spot detection: Spot Detection", "y", "Segmentation of small (<30 pixel) and large (>30 pixel) foci of intensity. Default: off.",14) // toggle spot detection on/offinput(IN_ROIarea, 4, "Minimum area for ROI: ROI detection", "i", "Minimum area threshold for SCC detection. Default: 4.") input(IN_ROI, 0, "ROI detection: Other Detection", "y", "Segmentation of large (>30 pixel) subcellular aggregates. Default: off.") // toggle spot detection on/off input(IN_ROIarea, 4, "Minimum area for ROI: Other detection", "i", "Minimum area threshold for SCC detection. Default: 4.") input(IN_ROIint, 1.5, "Minimum intensity for ROI: Other detection", "i", "Minimum intensity threshold adjustment factor for ROI detection, where threshold = (mean cell intensity in channel)*adjustment. Default: 1.") input(IN_ROIround, 0, "Minimum roundness for ROI: Other Detection", "i", "Range 0..1. Adjustment for roundness threshold applied to segmenting ROI; values approaching 0 tolerate non-round (irregular) regions. Default: 0") // roundness threshold for ROI input(IN_RefSEG, 0, "Include segmentation on reference image: Spot Detection", "y", "Attempt segmentation of sub-cellular structures using reference image. Default: off.",10) // toggle 1/2 for IM_1 input(IN_intensity, 0, "[INT] General intensity measurements: Features", "y", "Calculate intensity features on reference and signal channel(s). Default: off.", 15) // toggle intensity calculation suite on/off input(IN_morph, 0, "[MOR] General morphology measurements: Features", "y", "Calculate area, perimeter, and compactness features on reference image. Default: off.",16) // toggle morphology calculation suite on/off input(IN_Zone, 0, "Perinuclear zone segmentation: Other Detection", "y", "Define zone radiating out from nuclear border for intensity measurements. Only applies if intensity measurements are being calculated. Default: off.", 14.1) // define perinuclear space input(IN_ZoneCount, 3, "Perinuclear zone width: Other Detection", "i", "Pixel width of perinuclear zone. Default: 3 pixels.",14.2) // tune size of perinuclear zone for intensity measurements input(IN_Haralick, 0, "[TXT] Haralick texture features: Features", "y", "Haralick texture features.", 19) // toggle texture analysis on/off input(IN_HarStepNum, 1, " ..Number of steps in Haralick calculation: Features", "i", "Number of steps to use in Haralick calculations. Default: 1.",20) // adjust number of Haralick steps input(IN_TAS, 0, "[TXT] Threshold adjacency statistics: Features", "y", "Threshold adjacency statistics.", 21) // toggle texture analysis on/off input(IN_TRangeMode, 1, " ..TAS range mode: Features", "i", "Threshold adjacency statistics calculation range mode. 1, nine range points; 2, four range points; 3, two range points. Default: 1", 22) // TAS calculation restriction input(IN_TASmode, 1, " ..TAS output mode: Features", "i", "Threshold adjacency statistics calculation mode. 1, output all TAS steps; 2, every second step; 3, every third. Default: 1.", 23) // TAS feature output restriction input(IN_RadMom, 0, "[TXT] Radial moments: Features", "y", "Calculates the kth radial moment (given by the integral of (r^k)*I(r) where I(r) is the intensity of the object based on object radius) of detected objects highlighting either the center or border as defined by the user.", 24) // toggle texture analysis on/off input(IN_RefTXT, 0, "[TXT] Include texture analysis of reference image: Features", "y", "Measure texture features from reference image. Default: off.", 25) // toggle 2/2 for IM_1 input(IN_Pearsons, 0, "[CLC] Pearsons coefficient: Features", "y", "Calculates Pearson's coefficient, see Reference: Press, W.H., Flannery, B.P., Teukolsky, S.A. & Vetterling, W.T. (1988) Numerical Recipes in C. Cambridge University Press, Cambridge.", 26) // toggle colocalisation analysis on/off input(IN_Manders, 0, "[CLC] Manders coefficient: Features", "y", "Calculates Manders colocalisation values. See Reference:Manders, EEM, Verbeek, FJ., and Aten, JA. (1993). Measurement of co-localisation of objects in dual-colour confocal images. Journal of Microscopy 169, 375-382.", 27) // toggle colocalisation analysis on/off input(IN_ICQ, 0, "[CLC] ICQ coefficient: Features", "y", "Calculates ICQ colocalisation values. See Reference: Li, Qi, Lau, Anthony, Morris, Terence J., Guo, Lin, Fordyce, Christopher B., and Stanley, Elise F. (2004). A Syntaxin 1, G{alpha}o, and N-Type Calcium Channel Complex at a Presynaptic Nerve Terminal: Analysis by Quantitative Immunocolocalization. Journal of Neuroscience 24, 4070-4081.", 28) // toggle colocalisation analysis on/off input(OP_data, 0, "Write data to file: Output", "y", "Write object-level data as .txt file.", 29) // specify whether or not to write data files, default = no, in order to avoid accidental redundancy in OP files input(OP_stat, "Mean", "Statistic for well output: Output", "s", "Well-level feature output. Returns selected statistic for all features measured. Results will appear in Player window. If 'write data to file' is selected, results will also be written to file. Possible values: Mean, Median", 29.1) input(OP_destination, "default", "Target directory: Output", "s", "Destination directory for data output. By default, a new directory named 'output' will be created in the same location as the image data selected for analysis.", 30) // default given by dir from MBF_getinfo3() input(OP_treat, 0, "Save data by treatment: Output", "y", "Save object-level data in separate files according to treatment (defined below). Default: no separation, all data in single output file.", 31) // save data in multiple files according to multiple treatments input(OP_treatID, "Wellindex", "Filename treatment: Output", "s", "Treatment name to be used in output data filenames, if applicable. Possible values: Treatment_Sum, Treatment01, Treatment02, Treatment03, Wellindex. Default: NA.", 32) input(OP_imagecount, "5", "Number of object images to output (Mode 3): Output", "i", "Select the maximum number of object images per classification per field to be output. Used only if in Image Display mode. If set to 0, all object images will be generated. Default: 5.", 33) input(OP_FieldResult, "Not used", "Output field image (Mode 3): Output", "s", "Optional: output classification results as stencils on field image. Used only in Image Display mode. Possible values: Not used, All fields, Informative fields. A Field is considered informative only if multiple classification events are present within its object population. Default: off.", 34) input(OP_image2write, "Reference_image", "Signal image to output (Mode 3): Output", "s", "Select signal image to output in image gallery mode. Possible values: Reference_image, Signal_1, Signal_2, Signal_3, RGB", 35) set(IN_cleanup=1) // toggle on/off (1/0) to remove clutter from Data Explorer window set(IN_NAN=0) // toggle on/off (1/0) to remove NAN from output data ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(IN_mode=="Segmentation adjustment") set(IN_adjust=1, IN_fx=0, IN_gallery=0) end() if(IN_mode=="Feature extraction") set(IN_adjust=0, IN_fx=1, IN_gallery=0) end() if(IN_mode=="Image Display") set(IN_adjust=0, IN_fx=0, IN_gallery=1) end() set(ModeSelect=IN_adjust+IN_fx+IN_gallery) // 1.2 - OBLIGATE CODE singlewell(compact=yes) // 1.2.1 - EXPERIMENT INDEX (from MBF_GetInfo3 in MBF_ScriptBits.proc by Tony Collins) set(platemap_tab="null") if(length(wellIndex)==7) set(wellIndexLng="0"&wellIndex) else() set(wellIndexLng=wellIndex) end() // wellindex set(row=substr(wellIndexLng, 1,3 )+0) set(column=substr(wellIndexLng, 4,3 )+0) eval(set(tmp=sourcedata.sublayout[0])) if(errorcode>0) if(defined("sourcedata.field")) set(sourcedata.sublayout=sourcedata.field) else() foreach(1..sourcedata.rowcount, "rowcount") push(_sublayout, 1) end() //rowcount set(sourcedata.sublayout=_sublayout) delete(_sublayout, rowcount) end() // defined(sourcedata.field) end() // errorcode if(defined("sourcedata.field")) TableFilter("Field==1", table=sourcedata) else() TableFilter("sublayout==1", table=sourcedata) set(Table.Field=Table.sublayout) delete(table.sublayout) end() // defined(sourcedata.field) if(defined("sourcedata.Channel")) set(nCh=sourcedata.Channel.max) else() set(nCh=sourcedata.sourceimage.length) end() // defined(sourcedata.channel) if(defined("sourcedata.field")) set(fov=sourcedata.Field.max) else() set(fov=sourcedata.sublayout.max) end() // defined(sourcedata.field) set(nImages=sourcedata.@rowcount/fov) if(__version__>=26 && length(wellIndex) == 9) set(WellIndex=substr(WellIndex, 1, 6)) End() set (directoryStop=at(wellIndex, sourcedata.sourcefilename[0], -1)) set (dir=substr (sourcedata.sourcefilename[0], 0, directoryStop-1)) set(lastBackSlash=at("/",sourcedata.sourcefilename[0],-2)) set(exptFolder=substr(sourcedata.sourcefilename[0], 0, lastBackSlash)) set (firstSlash=at("/", sourcedata.sourcefilename[0], 1)) set (secondSlash=at("/", sourcedata.sourcefilename[0], 2)) if(defined("sourcedata.barcode")) set(barcode=sourcedata.Barcode[0]) else() set(barcode="NoBarcode") foreach(1..sourcedata.rowcount, "rowcount") push(_barcode, barcode) end() //rowcount set(sourcedata.barcode=_barcode) delete(_barcode, rowcount) end() // defined(sourcedata.barcode) set(skip=0) eval(readfile(filename=dir&"\\platemap.txt")) if(warningcode!=2050) readtable(filename=dir&"\\platemap.txt", fileformat="ascii", columns="firstrow", separators="\t") tablefilter("wellindex=="&wellindex, table=table) if(table.@rowcount>0) foreach(0..table.@columncount-1, "c") output(table.[c][0], table.@columns[c]) end() // c Insert_At(table, sourcedata.sourcefilename[0], "Path", 1) Insert_At(table, sourcedata.Barcode[0], "Barcode", 1) set(platemap_tab=table) else() // ie. if no "platemap.txt" is defined warning("Platemap is missing from image directory or "&wellindex&" is not accounted for!", confirm=no) set(skip=1) if(defined("table")) delete(table) end() create("table") insert_at(table, "temp", "temp") Insert_At(table, "Treatment03", "Treatment03", 1) Insert_At(table, "Treatment02", "Treatment02", 1) Insert_At(table, "Treatment01", "Treatment01", 1) Insert_At(table, "Treatment_Sum", "Treatment_Sum", 1) Insert_At(table, Column, "Column", 1) Insert_At(table, Row, "Row", 1) Insert_At(table, "Dye", "Dye", 1) Insert_At(table, "Cells", "Cells", 1) Insert_At(table, sourcedata.sourcefilename[0], "Path", 1) Insert_At(table, sourcedata.Barcode[0], "Barcode", 1) Insert_At(table, wellIndex, "WellIndex", 1) delete(table.temp, table.sourceimage, table.sourcefilename, table.frameindex, table.field) set(platemap_tab=table) end() // table.@columncount>0 end() //warningcode!2050 if(skip!=1) delete(barcode,directoryStop,errorcode,errors,errors_xml,firstSlash,lastBackSlash,secondSlash,table,warningcode,wellIndexLng) set(extensionpt=at(".", sourcedata.sourcefilename[0],-1)) set(exe=substr(sourcedata.sourcefilename[0],extensionpt+1)) if(exe!="flex") if(sourcedata.rowcount==1) if(IN_RGBCh1=="Not used") warning("Object reference channel for RGB image has not been assigned! Confirm channel assignment and try again.", confirm=yes) stop() else() if(IN_RGBCh1=="Blue") push(_RGB, "", "red", "green") end() // blue if(IN_RGBCh1=="Red") push(_RGB, "", "blue", "green") end() // red if(IN_RGBCh1=="Green") push(_RGB, "", "blue", "red") end() // green end() // not used set(image=sourcedata.sourceimage[0]) RGBsplit(image) set(IM_1=_[&IN_RGBCh1]) set(rc2=2) set(nCh=1) foreach(1..2, "rc") set(sigIM=_RGB[rc]) set(IMtest=_[&sigIM]) if(IMtest.max>0) set(_["IM_"&rc2]=_[&sigIM]) set(rc2=rc2+1) set(nCh=nCh+1) end() // image.max>0 end() // "rc" if(in_cleanup==1) delete(_RGB, rc, rc2,IMtest,sigIM) end() // cleanup end() // sourcedata.rowcount==1 end() // image is RGB ie. non-flex delete(exe, extensionpt) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 1.3 - CREATE OUTPUT DIRECTORIES if(!defined("dir")) set(dir="\\\mercury\operaimages\\"&OP_destination) else() set(date=__date__) set(datebreak1=at(".", date,1)) set(datebreak2=at(".", date,2)) set(dateyear=substr(date,datebreak2+1,4)) set(datemonth=substr(date,datebreak1+1,datebreak2-datebreak1-1)) set(dateday=substr(date,0,datebreak1)) set(date=dateyear&"."&datemonth&"."&dateday) set(dir2=dir&"\\output\\"&date&"_output") delete(datebreak1, datebreak2, dateyear, datemonth, dateday) end() // if defined dir if(OP_data==1 AND IN_mode=="Feature extraction") MkDir(dir2) end() //if OP_data == 1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 1.4a - IMAGE DISPLAY if(IN_gallery==1) eval(readfile(filename=dir&"\DirTemp.txt")) //eval(readfile(filename=dirIM&"\ClassificationCoordinates.txt")) if(warningcode!=2050) readfile(filename=dir&"\DirTemp.txt") set(content=substr(content,0,at("/",content,-1))) set(dirIM=content&"/ImageGallery_"&date) readtable(filename=dirIM&"\CoordinatesTemp.txt") set(filter=WellIndex*1) tablefilter("wellindex==filter", table=table) set(CoordinateTable=table) delete(table) else() getfiles() set(dirIM=substr(files[0],0,at("/",files[0],-1))) write(dirIM&"/", dir&"\DirTemp.txt", "ascii") set(dirIM=dirIM&"/ImageGallery_"&date) MkDir(dirIM) foreach(0..files.length-1, "fl") set(_["filename"&fl+1]=Files[fl]) set(IN_filename=Files[fl]) set(filetypebreak=at(".", IN_filename,-1)) set(filetype=substr(IN_filename,filetypebreak,4)) set(fileshortname=substr(IN_filename,0,filetypebreak)) if(filetype!=".dat") readtable(filename=IN_filename) stop() //writetable(table, dirIM&"\CoordinatesTemp.txt") else() eval(readfile(filename=fileshorstname&".txt")) if(errorcode==0) readtable(filename=fileshortname&".txt") end() // 0 ReadTable(filename=IN_filename, separators="\t") push(_columnheaders, "wellindex", "barcode", "dir", "platemap", "fov", "Xcoord", "Ycoord", "classification") foreach(1..table.rowcount-1, "t") //foreach(2..table.rowcount-1, "t") set(coord=table.A[t]) foreach(0.._columnheaders.length-1, "s") set(header=_columnheaders[s]) set(space=(8-s)*-1) set(headerspace=at(" ",coord,space)) if(s==7) push(_["index_"&s],substr(coord, headerspace)) //set(headervalue=1*substr(coord, headerspace)) else() set(spacediff=at(" ", coord, space+1)-headerspace) push(_["index_"&s],substr(coord, headerspace, spacediff)) //set(headervalue=1*substr(coord, headerspace, spacediff)) end() // s==7 end() // s end() // foreach t create("table") foreach(0.._columnheaders.length-1,"s") Insert_At(table, _["index_"&s],_columnheaders[s],table.length) delete(_["index_"&s]) end() // s delete(_columnheaders) eval(readfile(filename=dirIM&"\CoordinatesTemp.txt")) if(errorcode==2050) writetable(table,dirIM&"\CoordinatesTemp.txt") else() write(table,dirIM&"\CoordinatesTemp.txt","ascii", append=yes) end() // 2050 end() // if filetype!=.DAT set(_["table"&(fl+1)]=table) if(fl>0) appendtable(tableX, _["table"&(fl+1)]) set(tableX=table) else() set(tableX=table) end() //n>1 set(filter=WellIndex*1) tablefilter("wellindex==filter", table=tableX) set(CoordinateTable=table) delete(table) end() // "fl" end() // error2050 end() // IN_gallery ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 1.4 - INPUT FIELD OF VIEW if(!defined("fov")) set(fov=1) end() // if !defined fov if(IN_fov>fov) set(IN_fov=fov) end() // IN_fov>fov if(IN_fov>0) // analyze one field set(StartField = IN_fov) set(EndField = IN_fov) else() set(StartField=1) set(EndField=fov) end() // if IN_fov==0 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 1.5 - DETERMINE NUCLEAR REFERENCE ASSIGNMENTS if(IN_RGBCh1=="Not used") push(ChannelSeries1, "", "0", "1", "2", "3") push(ChannelSeries2, "", "0", "-1", "1", "2") push(ChannelSeries3, "", "0", "-2", "-1", "1") push(ChannelSeries4, "", "0", "-3", "-2", "-1") if(IN_Ch1==0) if(nCh>1) foreach(1..nCh, "j") // "j" used for same nCh loop below set(cam=substr(SourceData.name[j-1], 8,1 )+0) set(cam3=no) if(cam==3) set(nuc_ch=(j-1)) // if reference channel=ch_1, then (j-1)=0; if 2, then (j-1)=1, etc. set(ChannelSeries=_["ChannelSeries"&j]) delete("ChannelSeries1", "ChannelSeries2", "ChannelSeries3", "ChannelSeries4") set(cam3=yes) end() // if cam==3 if(cam3==no) set(IN_Ch1=1) end() //cam3=no delete(cam3) end() //foreach 1..nCh end() //if nCh>1 else() set(ChannelSeries=_["ChannelSeries"&IN_Ch1]) set(nuc_ch=IN_Ch1-1) end() // if IN_Ch1==1 end() // if IN_RGBCh1=="Not used" ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 1.6 MISCELLANEOUS INPUTS if(IN_ImageONOFF==1) set(_imageview="yes") else() set(_imageview="no") end() // if imageonoff =1 push(_signal, "", "Ch1", "Ch2", "Ch3", "Ch4") // by convention, Ch1 = IM_1, ie nuclear reference if(IN_cyto==0) set(IN_Stencil="Nucleus") end() //if(IN_cyto==0) if(IN_Stencil=="All") push(_stencil, "", "Nucleus", "Cytoplasm", "Cell") end() // IN_Stencil if(IN_Stencil=="Nucleus and Cytoplasm") push(_stencil, "", "Nucleus", "Cytoplasm") end() // IN_Stencil if(IN_Stencil=="Nucleus") push(_stencil, "", "Nucleus") end() // IN_Stencil if(IN_Stencil=="Cytoplasm") push(_stencil, "", "Cytoplasm") end() // IN_Stencil if(IN_Stencil=="Cell") push(_stencil, "", "Cell") end() // IN_Stencil set(fieldcount=0) if(IN_multinuc==1) set(IN_morph=1) end() // IN_multinuc==1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2. ANALYSIS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.1 - SIGNAL CHANNEL ASSIGNMENTS foreach(StartField..EndField, "i") if(IN_RGBCh1=="Not Used") if(IN_Ch1==0) if(nCh>1) foreach(1..nCh, "j") // "j" used for same nCh loop below set(_["IM_"&j]=SourceData.SourceImage[(i-1)*nCh+nuc_ch+ChannelSeries[j]]) // specify as signal of interest in channel "j" end() // for each nCh else() set(IM_1=SourceData.SourceImage[i-1]) end() // if nCh>1 else() foreach(1..nCh, "j") set(_["IM_"&j]=SourceData.SourceImage[(i-1)*nCh+nuc_ch+ChannelSeries[j]]) // specify as signal of interest in channel "j" end() // j end() // if IN_Ch1==0 end() // if IN_RGBCh1=="Not used" ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.2 - IMAGE QUALITY CHECKPOINT - OPTIONAL if(IN_gallery==1) set(IN_adjust=1) end() // IN_gallery if(IN_adjust==1) nuclei_detection_select(IM_1, yes) CalcIntensity(Image=IM_1, CalcStdDev=yes,objects=Nuclei)// Code by Santosh 11/13/2013 Set(Nuclei=Objects) if(IN_cyto==0) cytoplasm_detection_a(IM_1, no) else() if(IN_CytoRef!=1 AND IN_CytoRef<(nCh+1)) set(CytoRef=_["IM_"&IN_CytoRef]) else() set(CytoRef=IM_1) end() // IN_CytoRef==1 cytoplasm_detection_a(CytoRef, yes) delete(CytoRef) end() //IN_cyto CalcIntensity(Cytoplasm, IM_1, objects=Wholecells, CalcStdDev=yes) // Code by Santosh 11/13/2013 SetAttr("int_cont", nuclei.intensity/Objects.Cytoplasm_intensity, objects=objects) SetAttr("dev_cont", nuclei.intensity_stddev/Objects.Cytoplasm_intensity_stddev, objects=objects) Set(Wholecells=Objects) objectfilter(area>0, objects=wholecells) // MULTINUCLEUS DETECTION // adapted from multinucleation script courtesy Hind Azegrouz @ CNIC, Spain set(wholecells=objects) if(IN_multinuc==1) set(Nuclei1=Nuclei) calcerosion(-1, border, NumberOfSteps=3, objects=WholeCells, RestrictiveStencil=WholeCells.body) set(limit=objects.border_eroded.mask.image) Inverse(image=limit) set(limit=image-254) set(IM_nuc2=IM_1*limit) Nuclei_Detection_Select_2(IM_nuc2, yes) CalcStat("max", AttrName="belongtocell", Image=WholeCells.index, objects=Nuclei) // determine to which cell each nucleus belongs calcattr("belongtocell", "belongtocell-1") // correction for 0..n vs 1..n indexing (required?) CalcMassCentre() set(Nuclei2=objects) calcstat("sum", Image=Nuclei2.MassCentre.mask.image, objects=WholeCells, AttrName="multinucleicount") set(WholeCells=objects) set(Nuclei=Nuclei1) delete(Nuclei1, limit, image) end() //IN_multinuc set(objects=wholecells) If(objects.count>0) ObjectFilter((int_cont>IN_cont) OR (dev_cont>In_cont)) if(IN_Cont!=0) ImageView(Objects.border, "Cells after contrast filter", image=IM_1) end() End() if(objects.count>0) CalcMassCentre(objects=objects) SetAttr("aaFieldofView", filledvec(objects.@count, i)) SetAttr("aaYcoord", objects.MassCentre.y.target) SetAttr("aaXcoord", objects.MassCentre.x.target) set(fieldcount=fieldcount+1) calcattr(centers_area, nuclei.area[objectindex], objects=objects) calcattr(centers_contrast, nuclei.contrast[objectindex], objects=objects) calcattr(centers_intensity, nuclei.intensity[objectindex], objects=objects) set(_["obj_"&i]=objects) if(defined("all_cells")) addobjects(objects, DeleteGeometry=yes, objects=all_cells) set(all_cells=objects) else() set(all_cells=objects) end() //if defined all_count set(IM_blue=(255*IM_1/IM_1.max)) if(nCh>1) set(IM_green=(255*IM_2/IM_2.max)) if(nCh>2) set(IM_red=(255*IM_3/IM_3.max)) RgbJoin(red=IM_red, blue=IM_blue, green=IM_green) set(_["RGB_"&i]=image) delete("IM_red") else() RgbJoin(blue=IM_blue, green=IM_green) set(_["RGB_"&i]=image) end() // (nCh>2) delete("IM_green") else() RgbJoin(blue=IM_1) set(_["RGB_"&i]=image) end() // (nCh>1) delete("IM_blue") end() //object.count>0 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.2b - IMAGE DISPLAY CONT. if(objects.count>0) if(IN_gallery==1) set(dir3=dir2&"\\ImageGallery") if(OP_image2write=="Reference_image") set(IM_Category=IM_1) end() if(OP_image2write=="Signal_1") set(IM_Category=IM_2) end() if(OP_image2write=="Signal_2") set(IM_Category=IM_3) end() if(OP_image2write=="Signal_3") set(IM_Category=IM_4) end() if(OP_image2write=="RGB") set(IM_Category=_["RGB_"&i]) //set(text="white") end() tablefilter("fov*1==i", table=CoordinateTable) if(table.@rowcount!=0) set(table.Xcoord=table.Xcoord*1) set(table.Ycoord=table.Ycoord*1) set(CoordinateTableX=table) set(Categories=CoordinateTableX.classification*1) set(CategoriesCount=Categories.max) set(IN_FieldGallery=1) // bug patch 16 May 2012 - JY if(categories.max>3) warning("Classification results not drawn on whole field image -- too many categories present for optimal viewing (maximum 3 categories supported by Field Gallery Output module).") set(IN_FieldGallery=0) end() // categories.max>3 set(objects=_["obj_"&i]) foreach(0..objects.count-1, "oc") tablefilter(Xcoord==objects.aaXcoord[oc] AND Ycoord==objects.aaYcoord[oc], table=CoordinateTableX) if(table.@rowcount!=1) if(table.@rowcount>1) warning("Error in classified data set: multiple objects at same X and Y coordinate. Inspect input data set.", confirm=yes) stop() end() // multiple objects at a given X and Y if(table.@rowcount==0) push(_vecClass, 0) // warning("Error in classified data set: at least one object is missing an X and Y coordinate. Confirm segmentation parameters and try again.", confirm=yes) // stop() end() // no objects with the same X and Y else() push(_vecClass, table.classification[0]) end() // catch for multiple or no objects at input X and Y end() // oc calcattr(Category, _vecClass[objectindex], objects=_["obj_"&i]) delete(_vecClass) calcerosion(-1, cytoplasm_border, objects=objects) set(objects_all=objects) // FIELD OUTPUT if(OP_FieldResult!="Not used") set(OP_Field=0) if(OP_FieldResult=="Informative fields" AND categories.max>categories.min) set(OP_Field=1) else() if(OP_FieldResult=="All fields") set(OP_Field=1) end() // all fields end() // informative fields if(IN_FieldGallery!=1) set(OP_Field=0) end() //if(IN_FieldGallery!=0) ie if too many categories present for drawing results on field image if(OP_Field==1) MkDir(dirIM&"\FieldCollection\\"&OP_image2write) //set(IM_category=IM_2*255/(IM_2.mean)+3*(IM_2.stddev)) //set(IM_category=IM_2*255/IM_2.mean) //set(IM_category=_["RGB_"&i]) //set(IM_category=IM_2) //split(5000,image=IM_2) Mask(4095, image=IM_Category) set(IM_correct1=mask*IM_Category) set(IM_correct2=mask*4095) set(IM_temp=IM_Category-IM_correct1) set(IM_new=IM_temp+IM_correct2) rangemap(old_end=4095, new_end=255, fillrange=no, image=IM_new) set(IM_category=image) delete(IM_temp, IM_correct1, IM_correct2, IM_new) //gamma(image=image) //set(IM_category=image) push(_colour, "", "rgb(255,255,0)", "rgb(255,0,0)", "rgb(238,130,238)") foreach(1..Categories.max, "c") if(c<4) set(colour=_colour[c]) objectfilter(Category==c, objects=objects_all) if(objects.count>0) set(_["objects_category_"&c]=objects) //carrypixels(objects.Cytoplasm_border_eroded,200, image=IM_category) //carrypixels(objects.Cytoplasm_border_eroded, colour, image=image) carrypixels(objects.Cytoplasm_border, IM_category.max, image=IM_category) carrypixels(objects.Cytoplasm_border, colour, image=image) set(IM_category=image) end() // objects.count>0 end() // c<4 end() // c //ImageView(IM_category, "Signal image showing classification results for Field "&i, image=IM_category) ImageView(IM_category, OP_image2write&" image showing classification results for Field "&i, image=IM_category) //set(IM_temporary=IM_category) eval(readfile(dirIM&"\FieldCollection\\"&OP_image2write&"\\"&wellindex&"_F"&i)) if(warningcode==2050) if(OP_data==1) writeimage(dirIM&"\FieldCollection\\"&OP_image2write&"\\"&wellindex&"_F"&i&".jpg", image=IM_category, imageformat="jpg") end() // OP_data end() // warning code delete(_colour, colour) end() // OP_field==1 end() // OP_field result != not used // OBJECT-LEVEL IMAGE OUTPUT set(imagecount=OP_imagecount) //set(IM_category=IM_2*255/IM_2.max) //split(5000,image=IM_2) if(OP_image2write!="RGB") split(5000,image=IM_Category) delete(bright_image) gamma(image=image) set(IM_category=image) end() // if singlechannel image OP foreach(1..Categories.max, "c") //if(c<4) objectfilter(Category==c, objects=objects_all) if(objects.count>0) set(_["objects_category_"&c]=objects) set(objectstmp=_["objects_category_"&c]) if(OP_data==1) set(dir4=dirIM&"\\class_"&c&"\\"&OP_image2write) MkDir(dir4) end() // OP_data==1 if(objectstmp.count>imagecount) set(ObjectStart=floor((objectstmp.count-1)/2)-floor(imagecount/2)) set(ObjectEnd=floor((objectstmp.count-1)/2)+floor(imagecount/2)) else() set(ObjectStart=0) set(ObjectEnd=objectstmp.count-1) end() // ObjectLoop definition foreach(ObjectStart..ObjectEnd, "d") set(X=objectstmp.aaXcoord[d]) set(Y=objectstmp.aaYcoord[d]) objectfilter(aaXcoord==X AND aaYcoord==Y, objects=objectstmp) if(OP_image2write=="RGB") Mask2Stencil(objects.Cytoplasm_border.mask, "One large object") Palette_Gradual(middlecolor="white", startcolor="white", endcolor="white") ApplyPalette() CarryPixels(stencil, image, image=IM_Category) else() carrypixels(objects.Cytoplasm_border, IM_category.max, image=IM_category) carrypixels(objects.Cytoplasm_border, "white", image=image) end() // if RGB //carrypixels(objects.Cytoplasm_border, IM_category.max, image=IM_category) //carrypixels(objects.Cytoplasm_border, "white", image=image) set(FieldImage=image) crop(X-50, Y-50,X+50, Y+50, image=image) set(CropImage=image) //convelems(image, size=1) if(OP_data==1) //writeimage(dir4&"\\"&wellindex&"_F"&i&"_x"&X&"_y"&Y&".jpg", image=result, imageformat="jpg") writeimage(dir4&"\\"&wellindex&"_F"&i&"_x"&X&"_y"&Y&".jpg", image=image, imageformat="jpg") end() // OP_data end() // d end() //objects.count>0 //end() //// c<4 end() // c delete(image,IM_category,CategoriesCount,CoordinateTableX,objects,objects_all,objectstmp) //delete(image,IM_category,Categories,CategoriesCount,CoordinateTableX,objects,objects_all,objects_category_1,objects_category_2,objectstmp) //if(c==3) //delete(objects_category_3) //end() ////c==3 foreach(1..Categories.max, "c") delete("objects_category_"&c) end() // c delete(c, objectstart, objectend,Categories) end() // present well is in the coordinate table end() // IN_gallery end() // objects.count>0 (line407) else() // do all the work below ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.3 - OBJECT SEGMENTATION AND INITIAL MEASUREMENTS // 2.3.1 - NUCLEI DETECTION //if(isFlex==1) // Set(IN_ROI =1) //End() nuclei_detection_select(IM_1, no) calcattr(roundness, objects=nuclei) renameattr(compact=roundness) calcarea(border, objects=objects) CalcWidthLength() CalcIntensity(Image=IM_1, CalcStdDev=yes,objects=Objects) set(Nuclei=objects) // 2.3.2 - CYTOPLASM DETECTION if(IN_cyto==0) cytoplasm_detection_a(IM_1, no) else() if(IN_CytoRef!=1 AND IN_CytoRef<(nCh+1)) set(CytoRef=_["IM_"&IN_CytoRef]) else() set(CytoRef=IM_1) end() // IN_CytoRef==1 cytoplasm_detection_a(CytoRef, no) delete(CytoRef) end() CalcIntensity(Cytoplasm, IM_1, objects=Wholecells, CalcStdDev=yes) // Code by Santosh 11/13/2013 SetAttr("int_cont", nuclei.intensity/Objects.Cytoplasm_intensity, objects=objects) SetAttr("dev_cont", nuclei.intensity_stddev/Objects.Cytoplasm_intensity_stddev, objects=objects) Set(Wholecells=Objects) //IN_cyto objectfilter(area>0, objects=wholecells) deleteattr(area) if(IN_remove!="Not used") removeborderobjects(3, stencil=_["objects."&IN_remove], objects=objects) end() //IN_remove set(WholeCells=objects) // 2.3.2.1 - MULTINUCLEUS DETECTION // adapted from multinucleation script courtesy Hind Azegrouz @ CNIC, Spain if(IN_multinuc==1) set(Nuclei1=Nuclei) calcerosion(-1, border, NumberOfSteps=3, objects=WholeCells, RestrictiveStencil=WholeCells.body) set(limit=objects.border_eroded.mask.image) Inverse(image=limit) set(limit=(image-254)*WholeCells.body.mask.image) set(IM_nuc2=IM_1*limit) Nuclei_Detection_Select_2(IM_nuc2, no) CalcStat("max", AttrName="belongtocell", Image=WholeCells.index, objects=Nuclei) // determine to which cell each nucleus belongs calcattr("belongtocell", "belongtocell-1") // correction for 0..n vs 1..n indexing (required?) CalcMassCentre() set(Nuclei2=objects) calcstat("sum", Image=Nuclei2.MassCentre.mask.image, objects=WholeCells, AttrName="multinucleicount") set(WholeCells=objects) set(Nuclei=Nuclei1) delete(limit, IM_nuc2, Nuclei1) if(_imageview=="no") delete(Nuclei2) end() //_imageview end() //IN_multinuc set(objects=WholeCells) If(objects.count>0) ObjectFilter((int_cont>_.IN_cont) OR (dev_cont>_.IN_Cont)) if((IN_imageONOFF==1) AND (IN_Cont!=0)) ImageView(Objects.border, "Cells after contrast filter", image=IM_1) End() DeleteAttr(int_cont,dev_cont, cytoplasm_intensity, cytoplasm_intensity_stddev) End() if(objects.count>0) set(fieldcount=fieldcount+1) CalcMassCentre(objects=objects) SetAttr("aaFieldofView", filledvec(objects.@count, i)) SetAttr("aaYcoord", objects.MassCentre.y.target) SetAttr("aaXcoord", objects.MassCentre.x.target) //if(IN_ROI==0) //Set(ROIdone=1) //End() //If(!defined("ROIdone")) // Set(IN_ROI=1) //End() // ^ comment out by Jarkko 2014/07/14 if(IN_ROI==1) CalcMassCentre(centers, Weights=IM_1) // 20120330 - for ROI features SetAttr("aaYDNAcoord", objects.centers_MassCentre.y.target) // 20120330 - for ROI features SetAttr("aaXDNAcoord", objects.centers_MassCentre.x.target) // 20120330 - for ROI features deleteattr("NumberOfNuclei", objects=objects) end() // set(wholecells=objects) //if(IN_RefSEG==1) // set(ChStart=1) // set(ChEnd=nCh) // else() // set(ChStart=2) // set(ChEnd=nCh) //end() //// IN_RefSEG==1 if(IN_RefSEG!=1) if(nCh>1) set(ChStart=2) set(ChEnd=nCh) //set(ChEnd=2) // REMOVE THIS -- 20110323 else() set(ChStart=1) set(ChEnd=nCh) end() // nCh>1 else() set(ChStart=1) set(ChEnd=nCh) end() // IN_RefSEG!=1 if(_imageview=="yes") gamma(image=IM_1) set(gammaIM_1=image) //gamma(image=IM_nuc2) //set(gammaIM_nuc2=image) imageview(WholeCells.centers_border, "Nuclei", image=gammaIM_1, title="Nuclei for feature extraction") imageview(WholeCells.border, "WholeCells", image=gammaIM_1, title="Cells for feature extraction") if(IN_multinuc==1) paint(WholeCells.border, image=gammaIM_1) imageview(Nuclei2.border, "Nuclei2", image=image, title="Nuclei from second detection procedure") delete(Nuclei2, image) end() //IM_multinuc delete(gammaIM_1, image) end() //imageview // 2.3.3 - SPOT DETECTION if(IN_spots==1 OR IN_ROI==1) set(wholecellstemp=wholecells) set(stencilcount=1) if(IN_Stencil=="Nucleus and Cytoplasm" OR IN_Stencil=="All") Stencil2Objects(wholecells.centers) calcarea() set(WholeCells_1=objects) Stencil2Objects(wholecells.cytoplasm) calcarea() set(WholeCells_2=objects) set(stencilcount=2) end() // IN_Stencil = "Nucleus and Cytoplasm" if(IN_Stencil=="Nucleus") Stencil2Objects(wholecells.centers) calcarea() set(WholeCells_1=objects) end() // IN_Stencil = "Nucleus" if(IN_Stencil=="Cytoplasm") Stencil2Objects(wholecells.cytoplasm) calcarea() set(WholeCells_1=objects) end() // IN_Stencil = "Cytoplasm" if(IN_Stencil=="Cell") Stencil2Objects(wholecells.body) calcarea() set(WholeCells_1=objects) end() // IN_Stencil = "Cell" foreach(ChStart..ChEnd, "j") set(signal=_signal[j]) set(FieldImage=_["IM_"&j]) foreach(1..stencilcount, "e") //if(stencilcount==2) //set(stencilx=_stencil[e+1]) //else() set(stencilx=_stencil[e]) //end() ////stencilcount set(objects_stenciltemp=_["WholeCells_"&e]) //if(defined("ROIdone")) // comment out by Jarkko 2014/07/14 //set(IN_ROI=0) //end() // if(e==1) if(IN_ROI==1) calcintensity(image=FieldImage, objects=wholecellstemp) CalcMassCentre(Weights=FieldImage) // 20120330 - for ROI features renameattr(MassCentre_weighted=MassCentre) // 20120330 - for ROI features SetAttr("fluorYweighted", objects.MassCentre_weighted.y.target) // 20120330 - for ROI features SetAttr("fluorXweighted", objects.MassCentre_weighted.x.target) // 20120330 - for ROI features CalcErosion(-4, border, RestrictiveStencil=body) else() calcintensity(image=FieldImage, objects=objects_stenciltemp) end() // ROI==1 //calcintensity(image=FieldImage, objects=objects_temp) calcarea() set(objects_temp=objects) // 2.3.3.2 - LARGE SPOTS // adapted from MBFACA001 made for Sandra Nelson in March 2010 // modified for ROI features March 2012 if(IN_ROI==1) foreach(0..objects_temp.count-1, "c") // detect "large spots" one object at a time; c = cell counter set(body=objects_temp[c].body) // Mask2Stencil(body) // convert mask of object #c to stencil.. Stencil2Objects(Stencil) // .. and stencil to objectlist calcarea() // calculating area for the cell mask calcintensity(image=FieldImage, Total=no) // calculating intensity for the cell mask set(singleobject_temp=objects) set(singleimage=FieldImage*body.image) // define image to include signal found within current cell mask set(ROIthreshold=IN_ROIint*singleobject_temp.intensity.mean) // Modification Introduced By Santosh 11/6/2013 //cluster(IN_ROIarea, ROIthreshold, singleimage) // identify bright regions above given threshold, ie ROI Mask(threshold=ROIthreshold, image=singleimage) // Santosh 11/6/2013 Mask2Stencil() Stencil2Objects() CalcArea() CalcFillStencil() RenameAttr(unfilled=body) RenameAttr(body=filled) calcattr(roundness) if(IN_ROIarea>0) objectfilter(area>IN_ROIarea) // Area filter end() if(IN_ROIround>0) objectfilter(roundness>IN_ROIround) // roundness filter end() set(ROI=objects) if(ROI.count>0) //objectfilter(area0) push(_eulerMint, ROI.eulerM_totalintensity[em]/ROI.eulerM_count[em]) else() push(_eulerMint, 0) end() //if(SCC.eulerM_count[em]>0) // Fit ellipse to Objects Based on second moments - "Fitting an ellipse to an arbitrary shape: implications for strain analysis" Journal of Structural Geology 26 (2004) 143–153. Developed By Santosh 4/26/2012 CompAny(" (ROI[em].body.x - ROI[em].clusterXcoord)^2") //Set(diff_sq_Xtemp_sum = (ROI[em].body.x - ROI[em].clusterXcoord)^2) Set(diff_sq_Xtemp_sum=(result.sum)/ROI[em].area) //Set(diff_sq_Ytemp_sum = (ROI[em].body.y - ROI[em].clusterYcoord)^2) CompAny(" (ROI[em].body.y - ROI[em].clusterYcoord)^2") Set(diff_sq_Ytemp_sum=(result.sum)/ROI[em].area) Mul((ROI[em].body.y - ROI[em].clusterYcoord),(ROI[em].body.x - ROI[em].clusterXcoord)) Set(diff_sq_XYtemp_sum = result.sum/ROI[em].area) Set(com = sqrt((diff_sq_Xtemp_sum-diff_sq_Ytemp_sum)^2+(4*diff_sq_XYtemp_sum^2)) ) Set(MajorAxisTmp = sqrt(2*(diff_sq_Xtemp_sum+diff_sq_Ytemp_sum+com)/(ROI[em].area))) Set(MinorAxisTmp = sqrt(2*(diff_sq_Xtemp_sum+diff_sq_Ytemp_sum-com)/(ROI[em].area))) Set(eccentricityTmp = sqrt(MajorAxisTmp^2-MinorAxisTmp^2)/ MajorAxisTmp) Push(_majorAxis,MajorAxisTmp) Push(_minoraxis,MinorAxisTmp) Push(_eccentricity,eccentricityTmp) end() SetAttr("eccentricity", _eccentricity, objects=ROI) Set(ROI = Objects) Delete(_eccentricity,_minoraxis,_majorAxis) //foreach(0..SCC.count-1, "em") end() // ROI.count>0 if(ROI.count>0) // collect ROI attributes into vectors push(_ROIcount, ROI.count) push(_ROIarea, ROI.area.mean) push(_ROIareasum, ROI.area.sum) push(_ROIMemoverlap, ROI.edgeoverlap.sum/ROI.area.sum) push(_ROINucoverlap, ROI.nucoverlap.sum/ROI.area.sum) push(_ROIintensity, ROI.ROIintensity.mean) push(_ROIperimeter, ROI.perimeter.mean) push(_ROIroundness, ROI.roundness.mean) push(_ROIcof, ROI.COFdistance.mean) push(_ROIcof_nuclei, ROI.COFdistance_nuclei.mean) push(_ROIeulerT, ROI.count-eulerT.count) push(_ROIeulerM, ROI.count-ROI.eulerM_count.sum) push(_ROItransparency, ROI.ROItransparency.mean) Push(_ROIeccentricity,ROI.eccentricity.mean) if(ROI.count>1) // more than one ROI detected push(_ROIareavar, ROI.area.stddev^2) push(_ROIarearatio, (ROI.area.max/ROI.area.min)) push(_ROIcofvar, ROI.COFdistance.stddev^2) push(_ROIcofvar_nuclei, ROI.COFdistance_nuclei.stddev^2) If(ROI.COFdistance.min == 0) push(_ROIcofratio, 0) Else() push(_ROIcofratio, (ROI.COFdistance.max/ROI.COFdistance.min)) End() If(ROI.COFdistance_nuclei.min==0) push(_ROIcofratio_nuclei, 0) Else() push(_ROIcofratio_nuclei, (ROI.COFdistance_nuclei.max/ROI.COFdistance_nuclei.min)) End() else() push(_ROIareavar, 0) push(_ROIarearatio, 0) push(_ROIcofvar, 0) push(_ROIcofratio, 0) push(_ROIcofvar_nuclei, 0) push(_ROIcofratio_nuclei, 0) end() // if(objects.count>1) if(defined("ROITemp")) addobjects(ROI, CheckOverlap=no, DeleteGeometry=no, objects=ROItemp) // collect ROI attributes into objectlist set(ROITemp=objects) else() set(ROITemp=ROI) end() // if defined ROI else() // ie no ROI scored push(_ROIcount, 0) push(_ROIarea, 0) push(_ROIareasum, 0) push(_ROIMemoverlap, 0) push(_ROINucoverlap,0) push(_ROIareavar, 0) push(_ROIarearatio, 0) push(_ROIintensity, 0) push(_ROIperimeter, 0) push(_ROIroundness, 0) push(_ROIcof, 0) push(_ROIcofvar, 0) push(_ROIcofratio, 0) push(_ROIcof_nuclei, 0) push(_ROIcofvar_nuclei, 0) push(_ROIcofratio_nuclei, 0) push(_ROIeulerT, 0) push(_ROIeulerM, 0) push(_ROItransparency, 0) Push(_ROIeccentricity,0) end() //if objects.count>0 end() // foreach c if(IN_ImageONOFF==1) ImageView(FieldImage, signal) If(ROITemp.count>0) ImageView(ROITemp.body, "ROI Ch"&j, image=FieldImage) end() end() set(stencilx2="cell") // for clarity - 20120402 set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_Count"]=_ROIcount) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_AvgArea"]=_ROIarea) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_SumArea"]=_ROIareasum) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_MemOverlap"]=_ROIMemoverlap) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_NucOverlap"]=_ROINucoverlap) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_AvgPerimeter"]=_ROIperimeter) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_AvgRoundness"]=_ROIroundness) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_AvgIntensity"]=_ROIintensity) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_COFcell"]=_ROIcof) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_COFnuclei"]=_ROIcof_nuclei) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_EulerT"]=_ROIeulerT) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_EulerM"]=_ROIeulerM) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_AreaVariance"]=_ROIareavar) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_AreaRatio"]=_ROIarearatio) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_COFcellVariance"]=_ROIcofvar) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_COFnucleiVariance"]=_ROIcofvar_nuclei) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_COFcellRatio"]=_ROIcofratio) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_COFnucleiRatio"]=_ROIcofratio_nuclei) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_Transparency"]=_ROItransparency) set(_["wholecellstemp."&signal&"_MOR_"&stencilx2&"_ROI_Transparency"]=_ROIeccentricity) Delete(_ROICount,_ROIarea,_ROIareasum,_ROIMemoverlap,_ROINucoverlap,_ROIperimeter,_ROIroundness,_ROIintensity,_ROIcof,_ROIcof_nuclei,_ROIeulerT,_ROIeulerM,_ROIareavar,_ROIarearatio,_ROIcofvar,_ROIcofvar_nuclei,_ROIcofratio,_ROIcofratio_nuclei,_ROItransparency,_ROIeccentricity,) if(defined("ROITemp")) set(_["ROI_"&stencilx2]=ROITemp) end() //ROITemp //set(ROIdone=1) // comment out by Jarkko 2014/07/14 end() // if IN_ROI == 1 end() //e==1 // 2.3.3.1 - SMALL SPOTS if(IN_spots==1) spot_detection_a(FieldImage, "body", no, ShowOutputParameters=no, WholeCells=objects_stenciltemp) if(defined("ROITemp")) Inverse(image=ROITemp.body.mask.image) // adjust small spot count from Spot_Detection procedure above to remove overlap with ROI set(image=image-254) set(SpotCorrection=WholeCells.SpotCenters.mask.image*image) Mask(image=SpotCorrection) Mask2Stencil() Stencil2Objects() CalcMassCentre() set(SpotCorrection=objects.MassCentre.mask.image) calcintensity(body, SpotCorrection, objects=WholeCells, Total=yes) RenameAttr(SmallSpotCount=intensity) RenameAttr(SmallSpotAverageIntensity=SpotAverageCenterIntensity) DeleteAttr(SpotsArea) // adjust NumberOfSpots to include Large Spots but not Small Spots that coincide with the Large Spot masks //calcattr(NumberOfSpots, LargeSpots.count+SmallSpotCount) // adjust NumberOfSpots to include Large Spots but not Small Spots that coincide with the Large Spot masks set(WholeCellsSpotCorrected=objects) // WholeCell objectlist including spot data (but not all spot stencils) else() RenameAttr(SmallSpotCount=NumberOfSpots, objects=wholecells) RenameAttr(SmallSpotAverageIntensity=SpotAverageCenterIntensity) end() // defined ROITemp set(SmallSpots=spots) delete(integratedspotsignalperarea) set(_["SmallSpots_"&stencilx]=SmallSpots) if(IN_ImageONOFF==1) //foreach(ChStart..ChEnd, "j2") gamma(image=FieldImage) ImageView(image, signal) if(defined("SmallSpots")) set(spotstemp1=_["SmallSpots_"&stencilx]) convert(2, image=spotstemp1.border.mask.image) // output image of small spots into Acapella Player window set(IM_SpotMask=image) gamma(image=FieldImage) set(IM_Jadjusted=image) paint(IM_SpotMask, image=IM_Jadjusted) set(_["IM_view_small"&j]=image) imageview(_["IM_view_small"&j], "SmallSpots_"&stencilx&"_Ch"&j, delay@s=1) delete(spotstemp1) end() // defined smallspots // if(defined("ROITemp")) // set(spotstemp2=_["ROI_"&stencilx2]) // convert(2, image=spotstemp2.border.mask.image) // output image of large spots into Acapella Player window // gamma(image=_["IM_"&j2]) // set(IM_Jadjusted=image) // paint(image, image=IM_Jadjusted) // set(_["IM_view_large"&j2]=image) // imageview(_["IM_view_large"&j2], "ROI_"&stencilx&"_Ch"&j2, delay@s=1) // delete(_["IM_view_large"&j2], image, spotstemp2) // end() // // defined ROITemp delete(image, _["IM_view_small"&j], IM_SpotMask, IM_Jadjusted, SpotCorrection) //end() //// j2 //delete(j2) end() // if(IN_ImageONOFF==1) end() // IN_spots==1 // 2.3.3.3 - ADD SPOT DATA TO WHOLECELL OBJECT LISTS // 2.3.3.3.3 - RENAMING OF ATTRIBUTES //calcattr(spots_countestimate, objects.Spots_small_count[objectindex]+objects.Spots_large_count[objectindex]) if(IN_spots==1) set(_["wholecellstemp."&signal&"_MOR_"&stencilx&"_Spots_Small_Count"]=objects.SmallSpotCount) set(_["wholecellstemp."&signal&"_INT_"&stencilx&"_Spots_Small_AvgIntensity"]=objects.SmallSpotAverageIntensity) //foreach(0..objects.count-1, "c") // //push(_totalspot, objects.SmallSpotCount[c]+_LScount[c]) // push(_totalspot, objects.SmallSpotCount[c]) //end() //// c //delete(c) //set(_["wholecellstemp."&signal&"_MOR_"&stencilx&"_Spots_Total_Count"]=_totalspot) //delete(_totalspot) // end() // // IN_Spots==1 // else() //set(_["wholecellstemp."&signal&"_MOR_"&stencilx&"_Spots_Small_Count"]=wholecells.NumberOfSpots) //set(_["wholecellstemp."&signal&"_INT_"&stencilx&"_Spots_Small_AvgIntensity"]=wholecells.SpotAverageCenterIntensity) end() // IN_spots==1 //delete(_LSarea, _LScount, _LSintensity, _LSperimeter, _LSroundness, _totalspot) // PER FIELD OUTPUTS // if(defined("ROITemp")) delete(ROITemp) end() // defined ROITemp if(defined("SmallSpots")) delete(SmallSpots) end() // defined SmallSpots end() // foreach stencil "e" delete(FieldImage, e) end() // foreach ch delete(j, stencilcount) //deleteattr(aaXDNAcoord, objects=objects_temp) //deleteattr(aaYDNAcoord) //set(objects_temp=objects) //deleteattr(aaXDNAcoord, objects=wholecellstemp) //deleteattr(aaYDNAcoord) //set(wholecellstemp=objects) //deleteattr(aaXDNAcoord, objects=wholecells) //deleteattr(aaYDNAcoord) //set(WholeCells=objects) set(WholeCells=wholecellstemp) // 2.3.3.3.4 - EXPLORER CLEANUP if(IN_cleanup==1) Delete(image, body, objects, objects_temp, objects_stenciltemp, wholecellstemp, WholeCells_1, WholeCells_2, WholeCells_3, Stencil, SpotCorrection, mask, SpotCandidates, Spots, NumberOfSpotCandidates, NumberOfSpots,SpotsPerArea,SpotsPerObject,Spots_large_counter,Spots_small_counter,spots_large_area,spots_small_area, integratedspotssignalperarea, integratedspotsignalperarea_backgroundsubtracted, integratedspotsignalpercellularsignal, integratedspotsignalpercellularsignal_backgroundsubtracted, distance_vector, thld, ItemCount) if(IN_Spots==1) delete(WholeCellsSpotCorrected) end() //IN_Spots==1 end() // cleanup //Delete(ROIdone) // comment out by Jarkko 2014/07/14 end() // IN_spots ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.4 - INTENSITY MEASUREMENTS // 2.4.1 - INTENSITY BY COMPARTMENT if(IN_intensity==1) foreach(1..nCh, "j") // foreach channel set(signal=_signal[j]) set(image=_["IM_"&j]) if(IN_Stencil == "All" OR IN_Stencil == "Cell") calcintensity(body, image, CalcStdDev=yes, objects=WholeCells) set(_["wholecells."&signal&"_INT_Cell_intensity"]=objects.intensity) set(_["wholecells."&signal&"_INT_Cell_intensity_stddev"]=objects.intensity_stddev) deleteattr(intensity_stddev, objects=objects) end() // IN_Stencil = All or Cell if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Nucleus") calcintensity(centers, image, CalcStdDev=yes, objects=WholeCells) set(_["wholecells."&signal&"_INT_Nucleus_intensity"]=objects.centers_intensity) set(_["wholecells."&signal&"_INT_Nucleus_intensity_stddev"]=objects.centers_intensity_stddev) end() // IN_Stencil = All, Nucleus & Cytoplasm, or Nucleus if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Cytoplasm") calcintensity(Cytoplasm, image, CalcStdDev=yes, objects=WholeCells) set(_["wholecells."&signal&"_INT_Cytoplasm_intensity"]=objects.cytoplasm_intensity) set(_["wholecells."&signal&"_INT_Cytoplasm_intensity_stddev"]=objects.cytoplasm_intensity_stddev) end() // IN_Stencil = All, Nucleus & Cytoplasm, or Cytoplasm set(objects=wholecells) foreach(1..9, "u") set(quant=u/10) if(IN_Stencil == "All" OR IN_Stencil == "Cell") CalcStat("quantile", quant, body, Image=image) set(_["wholecells."&signal&"_INT_Cell_quantile"&(u*10)]=_["objects.quantile"]) end() if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Nucleus") CalcStat("quantile", quant, centers, Image=image) set(_["wholecells."&signal&"_INT_Nucleus_quantile"&(u*10)]=_["objects.quantile"]) end() if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Cytoplasm") CalcStat("quantile", quant, cytoplasm, Image=image) set(_["wholecells."&signal&"_INT_Cytoplasm_quantile"&(u*10)]=_["objects.quantile"]) end() end() //foreach u if(IN_Zone==1) // create perinuclear zone Stencil2Objects(wholecells.centers) calczone(IN_ZoneCount, objects=objects, ZoneType="standard") zonemask(filt_low=-1, filt_high=-3) renameattr(Nucleus_outerzone=zonemask) set(WholeCells_CentersZone=objects) calcintensity(nucleus_outerzone, image, CalcStdDev=yes, objects=WholeCells_CentersZone) set(_["wholecells."&signal&"_INT_PerinuclearZone_intensity"]=objects.nucleus_outerzone_intensity) set(_["wholecells."&signal&"_INT_PerinuclearZone_intensity_stddev"]=objects.nucleus_outerzone_intensity_stddev) if(IN_cleanup==1) delete(WholeCells_CentersZone) end() // cleanup end() // if IN_Zone=1 end() // intensities of each channel end() // if(IN_intensity==1) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.5 - MORPHOLOGY MEASUREMENTS if(IN_morph==1) set(objects=wholecells) // 2.5.1 - COMPACTNESS if(IN_Stencil == "All" OR IN_Stencil == "Cell") calcattr(roundness, objects=objects) renameattr(Ch1_MOR_Cell_compact=roundness) end() // IN_Stencil == "All" OR IN_Stencil == "Cell") if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Nucleus") calcattr(Ch1_MOR_Nucleus_compact, nuclei.compact[objectindex]) end() // IN_Stencil = All, or Nucleus & Cytoplasm, or Nucleus // 2.5.2 - AREA AND PERIMETER if(IN_Stencil == "All" OR IN_Stencil == "Cell") calcarea(border) renameattr(Ch1_MOR_Cell_area=area, Ch1_MOR_Cell_perimeter=border_area) calcattr(Ch1_MOR_Cell_perim2area, objects.Ch1_MOR_Cell_perimeter[objectindex]/objects.Ch1_MOR_Cell_area[objectindex]) end() // IN_Stencil == All, Cell if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Nucleus") calcattr(Ch1_MOR_Nucleus_perimeter, nuclei.border_area[objectindex]) calcarea(centers) renameattr(Ch1_MOR_Nucleus_area=centers_area) calcattr(Ch1_MOR_Nucleus_perim2area, objects.Ch1_MOR_Nucleus_perimeter[objectindex]/objects.Ch1_MOR_Nucleus_area[objectindex]) end() // IN_Stencil = All, Nuc & Cyto, Nucleus if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Cytoplasm") calcarea(cytoplasm) renameattr(Ch1_MOR_cytoplasm_area=cytoplasm_area) calcarea(cytoplasm_border) renameattr(Ch1_MOR_cytoplasm_perimeter=cytoplasm_border_area) calcattr(Ch1_MOR_cytoplasm_perim2area, objects.Ch1_MOR_cytoplasm_perimeter[objectindex]/objects.Ch1_MOR_cytoplasm_area[objectindex]) end() // IN_Stencil = all, nuc & cyto, cytoplasm // 2.5.3 - WIDTH AND LENGTH if(IN_Stencil == "All" OR IN_Stencil == "Cell") CalcWidthLength() renameattr(Ch1_MOR_Cell_fulllength=full_length, Ch1_MOR_Cell_halfwidth=half_width) end() // if(IN_Stencil == "All" OR IN_Stencil == "Cell") if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Nucleus") calcattr(Ch1_MOR_Nucleus_fulllength, nuclei.full_length[objectindex]) calcattr(Ch1_MOR_Nucleus_halfwidth, nuclei.half_width[objectindex]) end() // if(IN_Stencil == "All" OR IN_Stencil == "Nucleus and Cytoplasm" OR IN_Stencil == "Nucleus") if(IN_multinuc==1) renameattr(Ch1_MOR_Nucleus_multinucleicount=multinucleicount) end() //IN_multinuc set(wholecells=objects) end() // if(IN_morph==1) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.6 - TEXTURE FEATURE MEASUREMENTS if(IN_RefTXT==1) set(ChStart=1) set(ChEnd=nCh) else() set(ChStart=2) set(ChEnd=nCh) end() // IN_RefTXT==1 // 2.6.1 - STENCIL ASSIGNMENTS if(IN_Haralick==1 OR IN_TAS==1 OR IN_RadMom==1) if(IN_Stencil=="All") Stencil2Objects(wholecells.centers) calcarea() set(WholeCells_1=objects) Stencil2Objects(wholecells.cytoplasm) calcarea() set(WholeCells_2=objects) Stencil2Objects(wholecells.body) calcarea() set(WholeCells_3=objects) end() // IN_Stencil = all if(IN_Stencil=="Nucleus and Cytoplasm") Stencil2Objects(wholecells.centers) calcarea() set(WholeCells_1=objects) Stencil2Objects(wholecells.cytoplasm) calcarea() set(WholeCells_2=objects) end() // IN_Stencil = "Nucleus and Cytoplasm" if(IN_Stencil=="Nucleus") Stencil2Objects(wholecells.centers) calcarea() set(WholeCells_1=objects) end() // IN_Stencil = "Nucleus" if(IN_Stencil=="Cytoplasm") Stencil2Objects(wholecells.cytoplasm) calcarea() set(WholeCells_1=objects) end() // IN_Stencil = "Cytoplasm" if(IN_Stencil=="Cell") Stencil2Objects(wholecells.body) calcarea() set(WholeCells_1=objects) end() // IN_Stencil = "Cell" foreach(ChStart..ChEnd, "j") // foreach channel set(signal=_signal[j]) set(image00=_["IM_"&j]) foreach(1.._stencil.size-1, "e") set(stencilx=_stencil[e]) set(objects00=_["WholeCells_"&e]) set(signal=_signal[j]) // 2.6.2 - MOMENTS if(IN_RadMom==1) foreach(2..5, "v") CalcMoment(v, Image=image00, objects=objects00) set(_["wholecells."&signal&"_TXT_"&stencilx&"_moment"&v]=_["objects.moment"&v]) end() //foreach v // Radial Moments -- Created by Sean Cianflone, DWA lab, June 11, 2008; adapted from MBF_texture_suite.proc lines #495-553 by Jarkko Ylanko, MBF, December 9, 2010 foreach(1..2, "i3") if(i3==1) set(type="center") else() set(type="border") end() // if i3 set(original=image00) set(ROI_obj=objects00) set(k=2) calcstat("sum", stencil=ROI_obj.body, image=original) rename(ROI_obj_sum=objects) calczone(objects=ROI_obj, Stencil=body, ZoneType="standard") zoneimage(objects=objects) set(radial=zoneimage) CalcStat("max", Image=radial, objects=ROI_obj) set(ROI_obj=objects) blank(original.width, original.height, 1) convelems(image, "float", nonnumeric=0) carryobjects(ROI_obj.body, ROI_obj.max, image=result) rename(maxzone=image) set(stdradial=radial/maxzone) set(stdborderrad=((-1)*stdradial)+1) set(direction="C") if(type=="border") set(direction="B") set(radimage=stdborderrad) else() if(type=="center") set(radimage=stdradial) end() end() // type definition set(baseimage=radimage) foreach(1..k, "i2") set(_["mult"&0]=1) set(_["mult"&i2]=baseimage*_["mult"&(i2-1)]) end() //i2 - set set(image=_["mult"&k]) foreach(1..k, "i2") delete(_["mult"&i2]) end() //i2 - delete delete(_["mult"&0], i2) set(expedimage=image) calcintensity(Image=expedimage*original, Total=yes, objects=ROI_obj) blank(original.width, original.height, 0) convelems(image, "float", nonnumeric=0) carryobjects(ROI_obj.body, objects.intensity, image=result) set(radmoment=image) setAttr("Radial"&direction&k, objects.intensity/ROI_obj_sum.sum, objects=ROI_obj) rename(radialmom_obj=objects) DeleteAttr(max, objects=radialmom_obj) delete(appliedshift,baseimage,direction,expedimage,k,maxzone,non_numerics_count,original,radial,radialmom_obj,radimage,radmoment,result,ROI_obj,ROI_obj_sum,stdborderrad,stdradial,v,ZoneImage) if(i3==1) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_RadialC2"]=_["objects.RadialC2"]) else() set(_["WholeCells."&signal&"_TXT_"&stencilx&"_RadialB2"]=_["objects.RadialB2"]) end() // if i3==1 end() // i3 delete(v,i3, type) end() // if IN_RadMom = 1 // 2.6.3 - HARALICK FEATURES if(IN_Haralick==1) foreach(1..IN_HarStepNum, "r") // Haralick Features - Created by Tony Collins, MBF, 2008; adapted from MBF_texture_suite.proc lines #1-146 by Jarkko Ylanko, MBF, December 13, 2010 set(objects_in=objects00) set(in_image=image00) set(im_ref=image00) set(step=r) set(orientation="east") if(orientation=="north") set(xstep=0) set(ystep=-step) end() // north if(orientation=="east") set(xstep=step) set(ystep=0) end() // east if(orientation=="south") set(xstep=0) set(ystep=step) end() // south if(orientation=="west") set(xstep=-step) set(ystep=0) end() // west if(im_ref.elemtype==5) // if unsigned char set(signalHARALICK=im_ref) set(signalHARALICK.factor=1) else() convelems(im_ref, size=1, shiftnegative=yes, clipoutofrange=no, neginfinity=0, nonnumeric=0, allowfactorchange=1 ) set(signalHARALICK=result) set(signalHARALICK.factor=1) end() // elemtype==5 set(maxshift=iif(abs(xstep)>abs(ystep), abs(xstep), abs(ystep))) if(maxshift>1) blank(im_ref.width,im_ref.height,1) rectmask((abs(xstep)-xstep)/2, (abs(ystep)-ystep)/2, im_ref.width-(abs(xstep)+xstep)/2, im_ref.height-(abs(ystep)+ystep)/2,image=image) and(image=objects_in.body.image,mask=mask.image) Stencil2Objects(image) set(objects_corrected=objects_in) else() set(objects_corrected=objects_in) end() // maxshift>1 set(kernelwidth=iif(abs(xstep)>abs(ystep), 2*abs(xstep)+1, 2*abs(ystep)+1)) blank(kernelwidth,kernelwidth) set(image[(kernelwidth-1)/2+xstep,(kernelwidth-1)/2+ystep]=1) set(image.type="mask") set(kernel1=image.vector) convolution(image=signalHARALICK,convolutionkernel=kernel1) set(IM_neighbour=image) mul(signalHARALICK, 256,result_type="unsigned,short") plus(result,IM_neighbour,result_type="unsigned,short") and(image=result,mask=objects_corrected.body.mask.image) set(result=image) set(result.type="stencil") stencil2objects(result) calcarea() objectfilter(area>0) calcstat("max", attrname="I_pixel",stencil=body, image=signalHARALICK) calcstat("max", attrname="I_neighbour",stencil=body, image=IM_neighbour) set(IM_IntensityPairs=objects.body.image) // hold on - from line 82 of RC57, aka line 85 from RC117 deleteattr(area,body,border,index) set(OL_IntensityPairs=objects) Foreach(0..objects_corrected.count-1,"i2") objectfilter(objectindex==i2,objects=objects_corrected) set(ObjectArea=objects.area.sum) and(image= IM_IntensityPairs,mask=objects.body.mask.image) setattr(single_object,image.vector,objects=OL_IntensityPairs) calcarea(single_object) deleteattr(single_object) objectfilter(single_object_area) calcattr(f,1.0*single_object_area/ObjectArea) calcattr(asm,f*f) calcattr(contrast, f*(i_pixel-I_neighbour)*(i_pixel-I_neighbour)) calcattr(IDM, f/(1+(i_pixel-I_neighbour)*(i_pixel-I_neighbour))) calcattr(entropy,-f*ln(f)) push(asm_vec, 1.0*objects.asm.sum) push(contrast_vec, 1.0*objects.contrast.sum) push(IDM_vec, 1.0*objects.IDM.sum) push(entropy_vec, 1.0*objects.entropy.sum) push(sum_vec, 1.0*objects.f.sum) end() set(Haralick_table=tbl("Haralick_ASM_"& step=asm_vec, "Haralick_contrast_" & step=contrast_vec, "Haralick_IDM_"&step=IDM_vec, "Haralick_entropy_"&step=entropy_vec, "Haralick_sum_"&step=sum_vec)) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_ASM_"&r]=_["haralick_table.Haralick_ASM_"&r]) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_contrast_"&r]=_["haralick_table.Haralick_contrast_"&r]) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_entropy_"&r]=_["haralick_table.Haralick_entropy_"&r]) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_IDM_"&r]=_["haralick_table.Haralick_IDM_"&r]) delete("haralick_table",appliedshift,asm_vec,contrast_vec,entropy_vec,i2,IDM_vec,IM_IntensityPairs,IM_neighbour,im_ref,in_image,kernel1,kernelwidth,maxshift,non_numerics_count,ObjectArea,objects_corrected,objects_in,OL_Intensity,Pairs,orientation,result,step,sum_vec,xstep,ystep, signalHARALICK,OL_IntensityPairs) end() // foreach haralick step value r delete(r) end() // if IN_Haralick=1 // 2.6.4 - TEXTURE ADJACENCY STATISTICS //Timer(continue=true) if(IN_TAS==1) if(IN_TRangeMode==3) push(_TRange, "", "0.2", "0.4") // percentage of starting point pixels with neighbours of 0/1 = 1 end() // TRangeMode 1 if(IN_TRangeMode==2) push(_TRange, "", "0.2", "0.4", "0.6", "0.8") // percentage of starting point pixels with neighbours of 0/1 = 1 end() // TRangeMode 2 if(IN_TRangeMode==1) push(_TRange, "", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9") // percentage of starting point pixels with neighbours of 0/1 = 1 end() // TRangeMode 3 if(IN_TASmode==1) push(_TASmode,"",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36) // keep each TAS statistic end() //mode 1 if(IN_TASmode==2) push(_TASmode,"",2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36) // keep every other statistic end() //mode 2 if(IN_TASmode==3) push(_TASmode,"",3,6,9,12,15,18,21,24,27,30,33,36) // keep every third stat end() //mode 3 set(in_objects=objects00) set(in_image=image00) set(ratio_method="mean") blank(3,3,1) Set(image[1,1] = 10) // Use modified kernel instead of all 1 rename(kernel=image) //set(removeNAN="false") calcStat(ratio_method, Stencil=body, Image=in_image, objects=in_objects) blank(in_image.width, in_image.height) convelems(image, sign = "signed") if(ratio_method=="mean") carryobjects(in_objects.body, objects.mean, image=result) else() carryobjects(in_objects.body, objects.median, image=result) end() // ratio_method=mean set(img_avg=image) div(in_image, image, result_type="float", infinity=0,uncertainty=0) mask("inf", image=result) mul(not(mask), result, result_type= "float") set(ratio_image=result) foreach(1.._TRange.size-1, "s") set(TRange=_TRange[s]) set(TNum=100*TRange) // Texture Adjacency Statistic - Created by Tony Collins, MBF, 2008; adapted from MBF_texture_suite.proc lines #239-355 by Jarkko Ylanko, MBF, December 13, 2010 set(range=TRange) create("table") // Get different Ranges - Santosh 8/1/2014 foreach(0..3, "i3") if(i3==0) set(range_min=range) set(range_max=range) mask(1-range_min, image=ratio_image) set(mask1=mask) mask(1+range_max, image=ratio_image) set(mask2=mask) end() if(i3==1) set(range_min=range) set(range_max=ratio_image.max) mask(1-range_min, image=ratio_image) set(mask1=mask) mask(1+range_max, image=ratio_image) set(mask2=mask) end() if(i3==2) set(range_min=range) set(range_max=ratio_image.max) mask(1+range_min, image=ratio_image) set(mask1=mask) mask(1+range_max, image=ratio_image) set(mask2=mask) end() if(i3==3) set(range_min=0) set(range_max=ratio_image.max) mask(1-range_min, image=ratio_image) set(mask1=mask) mask(1+range_max, image=ratio_image) set(mask2=mask) end() minus(mask1, mask2) rename(mask_all=result) // Convolute Images convolution(image=mask_all, ConvolutionKernel=kernel, Faster=yes, ConvolutionKernelFactor=1) Set(adj_img=image) calcstat("sum", AttrName="tas_mTotal", Stencil=body, Image=mask_all, objects=objects) mul(adj_img, mask_all) Set(adj_img = result) // All values from 10-18 mapped to 0-8 neighbours foreach(1..9, "p") //mask(p, image=_["adj_mask"&i3]) //OC //mask(p, image=_["adj_mask"&i3]) //Set(rt = p+9) Set(mask = (adj_img== (p+9))) //set(mask3=mask) //mask(p+1, image=_["adj_mask"&i3]) //rename(mask4=mask) //minus(mask3, mask4, neg_method="zero") //set(_["m"& p]=result) //set(_["m"& p]=mask) if((i3*9)+p<10) set(pad="0") else() set(pad="") end() calcstat("sum", AttrName="tas", Stencil=body, Image=mask, objects=objects) Set(cl_nan=Objects.tas/Objects.tas_mTotal) MakeNanMap(cl_nan) ApplyNanMap(cl_nan, neginfinity=0, posinfinity=0) //SetAttr("tas"& pad & (i3*9)+p, result, objects=Objects) SetAttr("tas"& pad & (i3*9)+p&"_"&(range*100), result, objects=Objects) end() //p set(_["objects.tas_mTotal"&i3+1]=objects.tas_mTotal) end() // i3 // Redundant code - Santosh //foreach(1..36, "t") //if(t<10) //set(pad="0") //else() //set(pad="") //end() // t<19 //Insert_At(table, _["objects.TAS"& pad & t], "TAS"&pad & t & "_" & (range*100), table.columncount) //end() // t // M total is never used do not in output - Santosh Aug 1 2014 //foreach(1..3, "m") //Insert_At(table, _["objects.tas_mTotal"&m], "tas_mTotal"&m , table.columncount) //end() // m set(TAS_table=table) foreach(1.._TASmode.size-1, "m2") set(TASmode=_TASmode[m2]) if(TASmode<10) //set(_["WholeCells."&signal&"_TXT_"&stencilx&"_TAS_0"&TASmode&"_"&TNum]=_["TAS_table.TAS0"&TASmode&"_"&TNum]) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_TAS_0"&TASmode&"_"&TNum]=_["Objects.TAS0"&TASmode&"_"&TNum]) else() if(TASmode<28) //set(_["WholeCells."&signal&"_TXT_"&stencilx&"_TAS_"&TASmode&"_"&TNum]=_["TAS_table.TAS"&TASmode&"_"&TNum]) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_TAS_"&TASmode&"_"&TNum]=_["Objects.TAS"&TASmode&"_"&TNum]) else() //set(_["WholeCells."&signal&"_TXT_"&stencilx&"_TAS_"&TASmode]=_["TAS_table.TAS"&TASmode&"_"&TNum]) set(_["WholeCells."&signal&"_TXT_"&stencilx&"_TAS_"&TASmode]=_["Objects.TAS"&TASmode&"_"&TNum]) end() end() //if m2<10 end() // foreach TAS#, ie m2 //delete("TAS_table") end() // foreach TAS range value s delete(s, m2, TNum, TRange, _TRange, _TASmode, TASmode, _TRangeMode) end() //Timer(continue=false) //Set(RR=duration) // if(IN_TAS==1) end() //foreach 1..3 e end() //foreach 1..nCh j delete(adj_img,adj_mask0,adj_mask1,adj_mask2,appliedshift,i3,in_image,in_objects,kernel,m,m1,m2,m3,m4,m5,m6,m7,m8,m9,mask1,mask2,mask3,mask4,mask_all,non_numerics_count,p,pad,range,range_max,range_min,ratio_image,ratio_method,removeNAN,result,t,table,img_avg,image00,objects00) end() // if IN_textfeat=1 // 2.6.5 - CLEANUP if(IN_cleanup==1) delete(e,stencilx) delete(WholeCells_1,WholeCells_2,WholeCells_3) end() // cleanup ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.7 - SIGNAL COLOCALIZATION MEASUREMENTS if(IN_Pearsons==1 OR IN_Manders==1 OR IN_ICQ==1) ///////////////////////////////////// // 2.7.1 - TWO SIGNAL ANALYSIS // Rollingball background correction: Created by Tony Collins, MBF, 25 Sept 2006; adapted from MBF_BG_Correction.proc by Jarkko Ylanko, MBF, 14 December 2010 foreach(1..nCh, "cc0") set(im_cur=_["IM_"&cc0]) set(resizefactor=4) set(ballradius=15) resize(1/resizefactor, image=im_cur, yfactor=1/resizefactor) eros(edge=ballradius) resize(resizefactor, image=image, yfactor=resizefactor) set(backval = image.mean) set(xslip = (im_cur.width - image.width)/2) set(yslip = (im_cur.height - image.height)/2) redimension(im_cur.width, im_cur.height, xslip, yslip, backval, image=image, BackgroundMethod="mirror") set(BGimage = image) minus(im_cur, BGimage, neg_method="zero") set(BGCimage=result) set(_["IM_"&cc0&"bgc"]=BGCimage) end() // cc0 delete(cc0, im_cur, resizefactor, ballradius, backval, xslip, yslip, BGimage, BGCimage, result) foreach(1..nCh, "cc1") foreach(1..nCh, "cc2") if(cc1!=cc2 AND cc2>cc1) set(Ch1=_["IM_"&cc1&"bgc"]) set(Ch2=_["IM_"&cc2&"bgc"]) if(IN_Pearsons==1) // Pearsons Coefficient: created by Tony Collins, MBF, 25 Sept 2006; adapted from MBF_ColocalisationCoefficients b03.proc lines #1-128 by Jarkko Ylanko, MBF, 14 December 2010 set(ROI_obj=WholeCells) CalcIntensity(Image=Ch1, objects=ROI_obj, CalcStdDev=yes) rename(ROI_obj = objects) blank(Ch1.width, Ch1.height) convelems(image, sign = "signed") carryobjects(ROI_obj.body, ROI_obj.intensity, image=result) rename(Ch1m = image) minus(Ch1, Ch1m, result_type="long, signed") rename(Ch1subCh1m = result) CalcIntensity(Image=Ch2, objects=ROI_obj, CalcStdDev=yes) rename(Ch2_obj = objects) blank(Ch1.width, Ch1.height) convelems(image, sign = "signed") carryobjects(ROI_obj.body, Ch2_obj.intensity, image=result) rename(Ch2m = image) minus(Ch2, Ch2m, result_type = "long, signed") rename(Ch2subCh2m = result) mul(Ch2subCh2m, Ch1subCh1m, result_type = "long, signed") rename(PDM = result) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="unsigned") minus(PDM, 0, neg_method = "zero", result_type="float") set(PDM_pos_image = result) calcIntensity(Image = result, objects = ROI_obj, Total=yes) carryObjects(ROI_obj.body, objects.intensity, image = result) set(positive_PDM=image) mul(PDM, -1, result_type = "long") set(PDM_neg_image = result) minus(result, 0, neg_method = "zero", result_type="float") calcIntensity(Image = result, objects = ROI_obj, Total=yes) carryObjects(ROI_obj.body, objects.intensity, image = result) set(negative_PDM=image) minus(positive_PDM, negative_PDM, result_type = "float, signed") set(Pnumerator=result) mul(Ch1subCh1m, Ch1subCh1m, result_type = "float, signed") rename(Ch1subCh1mSqrd = result) calcIntensity(body, Ch1subCh1mSqrd,objects = ROI_obj, total=yes) rename( Ch1subCh1mSqrd_obj =objects) mul(Ch2subCh2m, Ch2subCh2m, result_type = "float, signed") rename(Ch2subCh2mSqrd = result) calcIntensity(body, Ch2subCh2mSqrd,objects = ROI_obj, total=yes) rename( Ch2subCh2mSqrd_obj =objects) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body, Ch1subCh1mSqrd_obj.intensity, image = result) rename(sumCh1subCh1mSqrd = image) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign= "signed") carryObjects(ROI_obj.body, Ch2subCh2mSqrd_obj.intensity, image = result) rename(sumCh2subCh2mSqrd = image) mul(sumCh2subCh2mSqrd, sumCh1subCh1mSqrd, result_type = "float, signed") CompAny("sqrt(result)") rename(Pdenominator = result) div(Pnumerator, Pdenominator, result_type="float") rename(Pearsons =result) calcIntensity(body,Pearsons, objects = ROI_obj) renameattr(PearsonsR=intensity, objects=objects) delete(appliedshift,Ch1m,Ch1subCh1m,Ch1subCh1mSqrd,Ch1subCh1mSqrd_obj,Ch2m,Ch2subCh2m,Ch2subCh2mSqrd,Ch2subCh2mSqrd_obj,Ch2_obj,negative_PDM,non_numerics_count,Pdenominator,PDM,PDM_neg_image,PDM_pos_image,Pearsons,Pnumerator,positive_PDM,ROI_obj,sumCh1subCh1mSqrd,sumCh2subCh2mSqrd) set(_["WholeCells.Ch"&cc1&"_CLC_Ch"&cc2&"_PearsonsR"]=objects.PearsonsR) end() // IN_Pearsons==1 if(IN_Manders==1) // Mander's Coefficients: created by Tony Collins, MBF, 25 Sept 2006; adapted from MBF_ColocalisationCoefficients b03.proc lines #206-325 by Jarkko Ylanko, MBF, 14 December 2010 set(ROI_obj=WholeCells) calcIntensity(body,Ch1, objects = ROI_obj, total=yes) rename(Ch1sum_obj = objects) calcIntensity(body,Ch2, objects = ROI_obj, total=yes) rename(Ch2sum_obj = objects) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body, Ch1sum_obj.intensity, image = result) rename(Ch1sum=image) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body, Ch2sum_obj.intensity, image = result) rename(Ch2sum=image) set(maskthresh=1) mask(image=Ch1, threshold=maskThresh, userealvalues=yes) rename(Ch1mask=mask) mask(image=Ch2, threshold=maskThresh, userealvalues=yes) rename(Ch2mask=mask) mul(Ch1, Ch2mask) rename(Ch1coloc = result) mul(Ch2, Ch1mask) rename(Ch2coloc = result) calcIntensity(body,Ch1coloc, objects = ROI_obj, total=yes) rename(Ch1coloc_obj = objects) calcIntensity(body,Ch2coloc, objects = ROI_obj, total=yes) rename(Ch2coloc_obj = objects) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body,Ch1coloc_obj.intensity, image = result) rename(Ch1colocsum=image) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body, Ch2coloc_obj.intensity, image = result) rename(Ch2colocsum=image) div(Ch1colocsum, Ch1sum, result_type="float") rename(M1=result) calcIntensity(body, M1, objects = ROI_obj) rename(M1_obj=objects) div(Ch2colocsum, Ch2sum, result_type="float") rename(M2=result) calcIntensity(body,M2, objects = ROI_obj) rename(M2_obj=objects) mul(Ch1, Ch2) rename(Ch1Ch2=result) calcIntensity(body, Ch1Ch2, objects=ROI_obj, Total=yes) rename(Ch1Ch2_obj=objects) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body,Ch1Ch2_obj.intensity, image = result) rename(Rnumerator=image) mul(Ch1,Ch1) rename(Ch1sqrd=result) calcIntensity(body, Ch1sqrd, objects=ROI_obj, Total=yes) rename(Ch1sqrd_obj=objects) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body,Ch1sqrd_obj.intensity, image = result) rename(Ch1sqrdsum=image) mul(Ch2,Ch2) rename(Ch2sqrd=result) calcIntensity(body, Ch2sqrd, objects=ROI_obj, Total=yes) rename(Ch2sqrd_obj=objects) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign="signed") carryObjects(ROI_obj.body,Ch2sqrd_obj.intensity, image = result) rename(Ch2sqrdsum=image) mul(Ch2sqrdsum,Ch1sqrdsum, result_type = "float, signed") CompAny("sqrt(result)") rename(Rdenominator = result) div(Rnumerator, Rdenominator,result_type="float") rename(MandersR =result) calcIntensity(body,MandersR, objects = ROI_obj) rename(MandersR_obj = objects) setAttr("M1", M1_obj.intensity, objects=ROI_obj) setAttr("M2", M2_obj.intensity, objects=objects) setAttr("MandersR", MandersR_obj.intensity, objects=objects) delete(appliedshift,Ch1Ch2,Ch1Ch2_obj,Ch1coloc,Ch1colocsum,Ch1coloc_obj,Ch1mask,Ch1sqrd,Ch1sqrdsum,Ch1sqrd_obj,Ch1sum,Ch1sum_obj,Ch2coloc,Ch2colocsum,Ch2coloc_obj,Ch2mask,Ch2sqrd,Ch2sqrdsum,Ch2sqrd_obj,Ch2sum,Ch2sum_obj,M1,M1_obj,M2,M2_obj,MandersR,MandersR_obj,maskthresh,non_numerics_count,Rdenominator,Rnumerator,ROI_obj) set(_["WholeCells.Ch"&cc1&"_CLC_Ch"&cc2&"_MandersR"]=objects.MandersR) set(_["WholeCells.Ch"&cc1&"_CLC_Ch"&cc2&"_M1"]=objects.M1) set(_["WholeCells.Ch"&cc1&"_CLC_Ch"&cc2&"_M2"]=objects.M2) end() // IN_Manders==1 if(IN_ICQ==1) //131-203 // Quantitative Immunocolocalization (ICQ): created by Tony Collins, MBF, 25 Sept 2006; adapted from MBF_ColocalisationCoefficients b03.proc lines #131-203 by Jarkko Ylanko, MBF, 15 December 2010 set(ROI_obj=WholeCells) CalcIntensity(Image=Ch1, objects=ROI_obj, CalcStdDev=no) rename(ROI_obj = objects) blank(Ch1.width, Ch1.height) convert(4,image=image) convelems(image, sign = "signed") carryobjects(ROI_obj.body, ROI_obj.intensity, image=result) rename(Ch1m = image) minus(Ch1, Ch1m, result_type="long, signed") rename(Ch1subCh1m = result) CalcIntensity(Image=Ch2, objects=ROI_obj, CalcStdDev=no) rename(Ch2_obj = objects) blank(Ch1.width, Ch1.height) convelems(image, "floating", sign = "signed") carryobjects(ROI_obj.body, Ch2_obj.intensity, image=result) rename(Ch2m = image) minus(Ch2, Ch2m, result_type = "long, signed") rename(Ch2subCh2m = result) mul(Ch2subCh2m, Ch1subCh1m, result_type = "long, signed") rename(PDM = result) minus( PDM, 0, result_type="automatic", neg_method="zero") rename(positive_images = result) mask(0.5, image=positive_images, userealvalues=yes) rename(positivePixels= mask) calcIntensity(body, positivePixels, objects=ROI_obj, Total=yes) rename(positive_obj = objects) blank(Ch1.width, Ch1.height) convelems(image, sign = "signed") carryObjects(ROI_obj.body, positive_obj.intensity, image = result) rename(ICQnumerator = image) blank(Ch1.width, Ch1.height) convelems(image, sign = "signed") calcAttr("area", objects=ROI_obj) carryObjects(ROI_obj.body, objects.area, image = result) rename(ICQdenominator = image) div(ICQnumerator, ICQdenominator, result_type="float") rename(ICQ = result) calcIntensity(body, ICQ, objects = ROI_obj) renameattr(ICQ=intensity, objects=objects) set(_["WholeCells.Ch"&cc1&"_CLC_Ch"&cc2&"_ICQ"]=objects.ICQ) delete(appliedshift,Ch2m,Ch2subCh2m,Ch2_obj,foreach_index,ICQ,ICQdenominator,ICQnumerator,non_numerics_count,PDM,positivePixels,positive_images,positive_obj,ROI_obj,Ch1m,Ch1subCh1m) end() // IN_ICQ==1 delete(Ch1,Ch2) end() // cc1!=cc2 AND cc2>cc1 end() // cc2 end() // cc1 foreach(1..nCh, "cc0") delete(_["IM_"&cc0&"bgc"]) end() // cc0 delete(cc0,cc1,cc2) ///////////////////////////////////// end() // if IN_Pearsons==1 OR IN_Manders==1 OR IN_ICQ==1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 2.8 - DATA ACCUMULATION if(defined("all_cells")) addobjects(wholecells, CheckOverlap=no, DeleteGeometry=yes, objects=all_cells) set(All_Cells=objects) else() set(All_Cells=wholecells) end() // if defined all_cells end() //if objects.count>0 end() // IN_adjust end() // start..endfield ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 3. DATA OUTPUT ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 3.1 - OUTPUT IF NO ANALYSIS PERFORMED if(defined("all_count")) output(all_count.count, "Preliminary object count") end() // 3.2 - OUTPUT IF ANALYSIS PERFORMED if(defined("all_cells")) if(defined("all_cells.NumberOfNuclei")) DeleteAttr(NumberOfNuclei, objects=all_cells) set(all_cells=objects) end() //numberofnuclei //CreateScalarAttrTable(all_cells) CreateAttrTableWithStat(Objects=all_cells) Set(ScaAttr =AttrTable ) If(OP_stat=="mean") TableFilter(rowindex==0, table=AttrTable) Else() TableFilter(rowindex==1, table=AttrTable) End() Delete(table.ObjectNo,ScaAttr) set(tablestat=table) CreateScalarAttrTable(all_cells) // Commented by Santosh Aug 1 2014 - Used //create("table") //foreach(0..AttrTable.@columncount-1,"sop") //insert_at(table, _["AttrTable."&AttrTable.@columns[sop]&"."&OP_stat], AttrTable.@columns[sop],table.@columncount) //end() //Foreach sop //delete(sop) set(table=attrtable) insert_At(table, filledvec(table.@rowcount, __date__), "DateOfAnalysis", 3) insert_At(table, table.aaFieldofView, "FieldofView", 0) insert_At(table, table.aaXcoord, "Xcoord", 1) insert_At(table, table.aaYcoord, "Ycoord", 2) delete(table.aaFieldofView,table.aaXcoord,table.aaYcoord) set(attrtable=table) set(table=tablestat) insert_At(table, All_Cells.@count, "ObjectCount", 3) insert_At(table, __date__, "DateOfAnalysis", 3) insert_At(table, attrtable.FieldofView.max, "FieldofView", 0) insert_At(table, "na", "Xcoord", 1) insert_At(table, "na", "Ycoord", 2) delete(table.aaFieldofView,table.aaXcoord,table.aaYcoord) set(tablestat=table) // 3.2.1 - INCLUSION OF PLATE INFORMATION if(defined("platemap_tab")) set(table_1=platemap_tab) set(table_2=attrTable) set(table_3=tablestat) if(table_1.@columncount==0) set(table=table_2) return() end() // empty table foreach(2..3, "op") if(op==3) set(table_1=platemap_tab) end() //op==3 set(tabletemp=_["table_"&op]) //if(table_1.@rowcount13) set(elem=_["OPtable." & OPtable.@columns[s] & ".elemtype"]) if(elem==13) set(value = OPtable.[s][0]) output(value,OPtable.@columns[s]) else() output(_["OPtable."& OPtable.@columns[s]&"."& stat],OPtable.@columns[s]) end() // elem=13 end() // ignore X, Y, fov end() // s delete(OP_stat, value, elem, s) //end() //// IN_fx==1 set(All_Data=table) end() // if defined all_cells // 3.2.4 - FIELD INFORMATION ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 4. EXPLORER CLEANUP ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(IN_cleanup==1) if(IN_gallery==1) delete(coordinatetable, cropimage, d, dir3, dir4, dirIM, appliedshift, errorcode, errors, errors_xml, fieldimage, filter, imagecount, non_numerics_count, oc, OP_Field, result, warningcode, X, Y) end() //in_gallery==1 //set(_["Field_"&i&"_Nuclei"]=Nuclei) //set(_["Field_"&i&"_WholeCells"]=WholeCells) //set(_["Field_"&i&"_Ch1"]=IM_1) //if(defined("IM_2")) // set(_["Field_"&i&"_Ch2"]=IM_2) delete(IM_2) //end() //// if defined IM_2 //if(defined("IM_3")) // set(_["Field_"&i&"_Ch3"]=IM_3) delete(IM_3) //end() //// if defined IM_3 delete(Nuclei,WholeCells,IM_1) delete(AttrTable,platemap_tab,blue,green,red,image,objects,_signal,_stencil) delete(IN_Ch1,IN_ChDefault,IN_colocal,IN_fov,IN_ImageONOFF,IN_RGB,IN_adjust,IN_spots,IN_textfeat,_imageview,signal,TotalCellArea,StartField,EndField,quant,OP_data,OP_destination,foreach_index,fieldcount,exptFolder,distance_vector,dir2,dir,u,nCh,nImages,i,j,IN_Haralick,IN_HarStepNum,IN_ICQ,IN_intensity,IN_LSpotThresh,IN_Manders,IN_morph,IN_Pearsons,IN_RadMom,IN_TAS,IN_TASmode,IN_Zone,IN_ZoneCount,c) delete(cam, content, IN_cyto, IN_LSpotRound, IN_ROI, IN_NAN, IN_RefSEG, IN_RefTXT, IN_Stencil, IN_TRangeMode, nuc_ch) delete(IN_cleanup, fov, IN_cytoRef, IN_fx, IN_gallery, IN_RGBCh1, OP_FieldResult, OP_imagecount, row,column, table, date, ChEnd, ChStart) delete(ChannelSeries) delete(OP_treat, OP_treatID, _OPtreatID) end() // cleanup end() // skip!=1 //************************************************************************* // File Name: objectfilter_WLE.proc // Product Version: $Id: ObjectFilter_wle.proc 18310 2007-11-09 17:49:23Z ollikaon $ // // Authors: Olavi Ollikainen // e-mail: Olavi.Ollikainen@perkinelmer.com // Copyright: (c) 2007 PerkinElmer Cellular Technologies // // Purpose: Procedures for objectfilter WLE spell // // Licences: Translocation Bundle //************************************************************************* proc ObjectFilter_wle_Control_outputNames( container _ inout) [hidden] { if(defined("HtmlViewSession")) if(defined("_spell.in.OutputObjectsName")) set(OutName_X=_spell.in.OutputObjectsName.value) if(OutName_X!="") eval("set(" & OutName_X & "=1)") if(errorcode>0) error("Error in the input name OutputObjectsName. Spaces are not allowed. Correct the name and click to run. To return to the automatic naming mode enter an empty string.") end() eval("delete(" & OutName_X & ")") end() end() end() } proc CreateAttrTableWithStat( objectlist objects in "Input object list", table AttrTable out "Table with scalar attributes", vector AttrVectors out "Vector with vector attribute names", vector AttrVectorsVector out) [hidden] { comment( set(AttrNames=objects.keys) if(objects.count>0) foreach(AttrNames) eval("set(a1=1.0*objects." & i &")") if(a1.class=="vector" and a1.class!="intervalvector" and a1.class!="indexvector" and i!="ObjectNO" and a1.elemtype<8) eval("calcattr(" & i & ",iif(inf==" & i & " or " & i & "!=" & i & ",0," & i & "))") end() end() end() ) create("table") if(objects.count>0) append(vec,0..objects.count-1) printfopen("0) set(a2=vec(a1.mean,a1.median,a1.stddev, a1.max, a1.min)) append(a2,a1) else() //set(a2=vec(0,0,0,0,0)) set(a2=vec(nan,nan,nan,nan,nan)) end() eval("set(table." & i & "=a2)") push(AttrVectors,i) push(AttrVectorsVector, a1) end() end() set(AttrTable=table) } proc CreateAttrTableTech( objectlist objects in "Input object list", double HtmlViewFactor in, table AttrTableTech out "Table with scalar attributes" ) [hidden] { create("table") if(!defined("objects.ObjectsNo")) calcattr(ObjectNo, 1*cellindex) end() set(obj1=objects) fillobjects() width_length_upto100(objects) calcattr(xcoord, 1.0*HtmlViewFactor*center_spot.x[0],DefaultValue=0) calcattr(ycoord, 1.0*HtmlViewFactor*center_spot.y[0],DefaultValue=0) calcattr(radius, HtmlViewFactor*(full_Length/2+2*(Half_Width+1))/3) set(table.ObjectNo=objects.ObjectNo) set(table.X=objects.xcoord, table.Y=objects.ycoord, table.R=objects.radius) set(objects=obj1) set(AttrNames=objects.keys) foreach(AttrNames) set(a1=objects[i]) //if(a1.class=="vector" and a1.class!="intervalvector" and a1.class!="indexvector" and a1.elemtype<8 ) if(a1.class=="vector" and a1.class!="intervalvector" and a1.class!="indexvector") set(table[i]=a1) end() end() set(AttrTableTech=table) } proc CreateFilterSet( objectlist objects in "Input object list", container FilterSet out "Container with filter set data") [hidden] { create("container") set(FilterSet=container) set(AttrNames=objects.keys) foreach(AttrNames) eval("set(a1=objects." & i &")") if(a1.class=="vector" and a1.class!="intervalvector" and a1.class!="indexvector" and i!="ObjectNO" and a1.elemtype<8) if(a1.length>0) set(a1min=a1.min, a1max=a1.max) else() set(a1min=0, a1max=0) end() set(a1minabs=0.00000001*abs(a1min), a1maxabs=0.00000001*abs(a1max)) eval("set(FilterSet." & i & "=container)") eval("set(FilterSet." & i & ".ONOFF=FALSE)") eval("set(FilterSet." & i & ".MIN=a1min)") eval("set(FilterSet." & i & ".MAX=a1max)") eval("set(FilterSet." & i & ".FMIN=a1min-a1minabs)") eval("set(FilterSet." & i & ".FMAX=a1max+a1maxabs)") end() end() } proc CreateAttrTableWithFilt( objectlist objects in "Input object list without class attributes", objectlist cl_class_attr in "Input object list with class attributes, attribute names should correspond to FilterSet container", container filterset in "Input container, which defines the filters", table AttrTable out "Output tabel with scalar attributes and filter settings", vector AttrVectors out "Vector with vector attribute names", vector AttrVectorsVector out) [hidden] { set(NumberOfObjects=objects.count) create("table") if(NumberOfObjects>0) append(vec,0..objects.count-1) printfopen("0) set(a2=vec(a1.mean,a1.median,a1.stddev, a1.max, a1.min)) else() set(a2=vec(nan,nan,nan,nan,nan)) end() eval("set(fs1=filterset." & i & ".ONOFF , fs2=filterset." & i & ".FMIN, fs3=filterset." & i & ".FMAX)") if(errorcode==0) if(fs1=="ON") push(a2,1,fs2,fs3, NumberOfObjects) eval("set(fs4=cl_class_attr.filter_" & i & ".sum)") if(errorcode==0) push(a2,fs4) else() push(a2,NumberOfObjects) end() else() push(a2,0, fs2, fs3, NumberOfObjects, NumberOfObjects) end() else() push(a2,nan,nan,nan, NumberOfObjects , NumberOfObjects) end() if(NumberOfObjects>0) append(a2,a1) end() eval("set(table." & i & "=a2)") push(AttrVectors,i) push(AttrVectorsVector, a1) end() end() set(AttrTable=table) } proc ObjectFilter_WLE_control(container _ inout) [hidden] { if(!defined("Objects")) set(errors=" Input Objects is missing. Evaluation is stopped. Select the input Objects and click to run.") set(errorcode=6504007) error() end() if( defined("HtmlViewSession")) set(lista=_spell.in) set(OutputName2=lista.objects.value) set(startpos=at(".", OutputName2,2)) set(OutputObjectsName2=substr(lista.objects.value,startpos+1, OutputName2.length-startpos) & "_Filtered") if(!defined("OutputObjectsName")) set(list=_spell.in) set(cont_temp=cnt(value=OutputObjectsName2,type="scalar", title="Name of output object list. By default to input list name is added suffix Filtered. If the input list is changed the name of output one is updated automatically during the first run. After the output name is changed manually the atomatic name update switches off. To return to the automatic mode enter empty string.")) WizardInsertListElement("OutputObjectsName", "NumberOfDefinitions", cont_temp) set(_spell.in=list) set(_spell.my1=OutputObjectsName2, _spell.my2=OutputObjectsName2) delete(lista,list,OutputName2, startpos ) else() if(OutputObjectsName!=OutputObjectsName2) if(OutputObjectsName==_spell.my2 or OutputObjectsName=="") set(list=_spell.in) set(_spell.in.OutputObjectsName.value=OutputObjectsName2) //WizardDeleteListElement("OutputObjectsName") //WizardPushVar("OutputObjectsName","scalar", OutputObjectsName2, title="Name of output object list. By default to input list name is added suffix Filtered. If the input list is changed the name of output one is updated automatically during the first run. After the output name is changed manually the atomatic name update switches off. To return to the automatic mode enter empty string.")) //set(_spell.in=list) set(_spell.my1=OutputObjectsName2, _spell.my2=OutputObjectsName2) set(OutputObjectsName=OutputObjectsName2) delete(list) else() set(_spell.my2=OutputObjectsName2) set(_spell.my1=OutputObjectsName) set(OutputObjectsName2=OutputObjectsName) end() end() else() set(OutputObjectsName2=OutputObjectsName) end() else() set(OutputObjectsName2=OutputObjectsName) end() } proc ObjectFilter_wle4( container _ inout ) [hidden] { if( defined("HtmlViewSession")) set(list=_spell.in) set(_next=list.OutputObjectsName._next) while(_next!="_last") set(elem=list[_next]) push(atest,_next) WizardDeleteListElement(_next) set(_next=elem._next) end() end() set(ObjectsBeforeFilters=objects.count) CreateFilterSet(objects) // Creates a filterSet container for all numeric attributes in object list set(AttrNames=filterset.keys) set(text_title1=". ON-Filter is on; OFF- filter is off.") set(text_title2="Minimum limit. Default value is equal to the minimum attribute value.")// i.e. all objects have attribute value higher than default one.") set(text_title3="Maximum limit. Default value is equal to the maximum attribute value.")// i.e. all objects have attribute value smaller than default one.") foreach(AttrNames) if( defined("" & i)) // if filter is defined eval("set(minelem=filterset." & i & ".FMIN, maxelem=filterset." & i & ".FMAX)") eval("set(ivalue=" & i & ", iminvalue=" & i & "_FMIN, imaxvalue=" & i & "_FMAX)") eval("set(filterset." & i & ".ONOFF=" & i &")") eval("set(filterset." & i & ".FMIN=" & iminvalue & ")") eval("set(filterset." & i & ".FMAX=" & imaxvalue & ")") set(text_title0="Filter, attribute " & i) if( defined("HtmlViewSession")) if(ivalue=="ON") WizardPushVar(i ,"scalar", vec("ON","OFF"), text_title0 & text_title1 ) else() WizardPushVar(i ,"scalar", vec("OFF","ON"), text_title0 & text_title1 ) end() WizardPushVar(i & "_FMIN","scalar",iminvalue, text_title2) WizardPushVar(i & "_FMAX","scalar",imaxvalue, text_title3) end() else() if(defined ("objects." & i ) ) eval("set(a1=objects." & i & ")") if ( a1.class=="vector" and a1.class!="intervalvector") set(text_title0="Filter, attribute " & i ) if( defined("HtmlViewSession")) WizardPushVar(i,"scalar", vec("OFF","ON"), text_title0 & text_title1) end() eval("set(a1min=filterset." & i & ".FMIN)") eval("set(a1max=filterset." & i & ".FMAX)") set(i1=i & "_FMIN", i2=i & "_FMAX") if( defined("HtmlViewSession")) WizardPushVar(i1,"scalar", a1min, text_title2) WizardPushVar(i2,"scalar", a1max, text_title3) end() end() end() end() end() if(defined("VisualImage")) set(visualImage.factor=1.0) gamma(2.6, image=visualImage) carrypixels(image=image, mask=objects.border, data=image.max) else() blank(objects.body.image.width, objects.body.image.height) carrypixels(image=image, mask=objects.border, data=255) end() if( defined("HtmlViewSession")) set(_spell.in=list) if(Operation!="none") if(Operation=="DefaultsToMinMax") SetDefaultsToMinMax() else() if(Operation=="AllFiltersOFF") SetAllFiltersOFF() else() SetAllFiltersON() end() end() set(_spell.in.Operation.value="none") end() set(list=_spell.in) end() ApplyFilterSet2() CreateAttrTableWithFilt() //objects, cl_class_attr, set(AttributeTableBeforeFilters=AttrTable) set(HtmlViewFactor=1.0) CreateAttrTableTech(cl_class_attr_text, HtmlViewFactor) CreateAttrTableWithStat() set(AttributeTableAfterFilters=AttrTable) set(objects=cl_filtered) set(ObjectsAfterFilters=objects.count) if(objects.count>0) carryobjects(image=image, stencil=objects.border, shuffle=yes,data="rainbow") end() set(FilterImage_hidden=image) if(!defined("HtmlViewSession")) //Output illustration for dewizardized script if(!defined("ShowIllustrations")) set(ShowIllustrations=NO) end() if(!defined("SpellNameSuffixDewizard")) set(SpellNameSuffixDewizard="") end() if(ShowIllustrations) imageview(FilterImage_hidden,"ObjectFilter" & SpellNameSuffixDewizard,image=FilterImage_hidden, title="Object filters. White: discarded objects. Objects before: " & ObjectsBeforeFilters & ", after: " & ObjectsAfterFilters) end() end() //set(OutputName2=list.objects.value) //set(startpos=at(".", OutputName2,2)) //set(OutputName=substr(list.objects.value,startpos+1, OutputName2.length-startpos)) eval("set(" & OutputObjectsName2 & "=Objects)") //CreateAttrTableWithStat(objects) //set(FilterImage="
Objects after filters. With white are marked discarded objects
") if( defined("HtmlViewSession")) set(_spell.in=list) delete(list) end() delete(list) } proc ApplyFilterSet( objectlist objects inout "Input object list", container FilterSet in "Container with filter set data") [hidden] { set(AttrNames=filterset.keys) foreach(AttrNames) eval("set(a1=FilterSet." & i &")") if(a1.ONOFF) eval("cellfilter(a1.FMIN<= " & i & " and "& i & " <=a1.FMAX)") end() end() } proc ApplyFilterSet2( objectlist objects in "Input object list", container FilterSet in "Container with filter set data", objectlist cl_class_attr out "Object list with all objects and with calculated class attributes", objectlist cl_class_attr_text out "Object list with all objects and with calculated class attributes in text form", objectlist cl_filtered out "Object List of filtered objects" ) [hidden] { set(AttrNames=filterset.keys) set(cl_filtered=objects, cl_class_attr=objects, cl_class_attr_text=objects) foreach(AttrNames) eval("set(a1=FilterSet." & i & ")") if(a1.ONOFF) set(tx1="Filter_" & i) //eval("set(tx1=tx1 & i & ")") eval("calcattr(" & tx1 & ", a1.FMIN<=" & i & " and " & i & " <=a1.FMAX, objects=cl_class_attr)") set(cl_class_attr=objects) eval("calcattr(temporal,iif(" & tx1 & "==1, \"TRUE\",\"FALSE\"))") eval("setattr(" & tx1 & ",objects.temporal, objects=cl_class_attr_text)") set(cl_class_attr_text=objects) eval("cellfilter(a1.FMIN<= " & i & " and " & i & " <=a1.FMAX, objects=cl_filtered)") set(cl_filtered=objects) end() end() } proc SetDefaultsToMinMax( container _spell inout "Spell container", container FilterSet inout "Input-output FilterSet container", objectlist objects in "Object list with attributes" ) [hidden] { set(AttrNames=filterset.keys) if(objects.count>0) foreach(AttrNames) set(FilterSet[i]["FMIN"]=objects[i].min ) set(FilterSet[i]["FMAX"]=objects[i].max ) eval("set(_spell.in." & i & "_FMIN.value=FilterSet[i][\"FMIN\"])") eval("set(_spell.in." & i & "_FMAX.value=FilterSet[i][\"FMAX\"])") //set(_spell.in.[i & "_FMAX"]["value"]=FilterSet[i]["FMAX"]) end() end() } proc SetAllFiltersOFF( container _spell inout "Spell container", container FilterSet inout "Input-output FilterSet container", objectlist objects in "Object list with attributes" ) [hidden] { set(AttrNames=filterset.keys) //if(objects.count>0) foreach(AttrNames) set(FilterSet[i]["ONOFF"]=0) eval("set(_spell.in." & i & ".value=\"OFF\")") end() //end() } proc SetAllFiltersON( container _spell inout "Spell container", container FilterSet inout "Input-output FilterSet container", objectlist objects in "Object list with attributes" ) [hidden] { set(AttrNames=filterset.keys) //if(objects.count>0) foreach(AttrNames) set(FilterSet[i]["ONOFF"]=1) //eval("set(_spell.in." & i & ".value=\"ON\")") set(_spell.in[i]["value"]="ON") end() //end() } proc ObjectFilter_WLE_CreatePrivatINPHP (string privateinphp out) [hidden] { set(privateinphp="""{ $_inputs_struct_start=&$GLOBALS[$_spell]['inputs_struct_start']; $_inputs_struct_start_hidden=&$GLOBALS[$_spell]['inputs_struct_start_hidden']; echo "\n"; if($_thisin != "_last") { echo ""; hiddenpar("$_spell.inputs_struct_start_hidden.$_thisin",$_inputs_struct_start_hidden[$_thisin]); echo ""; } $_this=$_inputs[$_thisin]; $_type="$_this[type]"; $_value="$_this[value]"; $_title="$_this[title]"; showinputvar($_thisin,$_type,$_value,$_spell,$_title,$_this['vlist']); $_thisin=$_inputs[$_thisin]['_next']; } echo ""; } else { echo "\n"; }") } proc ObjectFilter_WLE_Create_inputs_struct_start(container SpellContainer inout) [hidden] { set(epsilon=0.00001) create("container") set(SpellContainer2=SpellContainer) set(SpellContainer.inputs_struct_start=container) set(SpellContainer.inputs_struct_start_hidden=container) set(SpellContainer.inputs_struct_start.Objects="General") set(SpellContainer.inputs_struct_start_hidden.Objects=eval("SpellContainer2.inputs_struct_start_hidden.Objects",0)) set(i2=0, i3=1) set(list=SpellContainer.in) if(defined("list.OutputObjectsName")) set(_next=list.OutputObjectsName._next) while(_next!="_last") if(3*floor(i2/3+epsilon)==i2) set(attributex=_next) //set(attributex2=substr(_next,1, _next.length-6)) //set(SpellContainer.inputs_struct_start[_next]="Filter " & i3 & ", " & attributex) //set(SpellContainer.inputs_struct_start[_next]="Filter, " & attributex) set(SpellContainer.inputs_struct_start[_next]=attributex & ", Filter " & i3) set(SpellContainer.inputs_struct_start_hidden[_next]=eval("""{SpellContainer2.inputs_struct_start_hidden[_next]}",1)) set(i3=i3+1) end() set(elem=list[_next]) set(_next=elem._next) set(i2=i2+1) end() end() } proc ObjectFilter_WLE_MAIN(container _ inout) [hidden] { ObjectFilter_wle_Control_outputNames() ObjectFilter_WLE_control() ObjectFilter_wle4() if(defined("HtmlViewSession") ) ObjectFilter_wle_visual() ObjectFilter_WLE_CreatePrivatINPHP () set(_spell.privateinphp=privateinphp) ObjectFilter_WLE_Create_inputs_struct_start(_spell) set(_spell=SpellContainer) end() } proc ObjectFilter_wle_html_code(container _ inout ) [hidden] { if(zoom) set(HtMLImageWithZoom="""{
  ShowHide   Zoom  
Zoomed image with object borders
}" & ZoomBox & "
" & ZoomBox2 & """{
Zoomed Visual Image
Detected Nuclei
}" & HintMap & Figuretext & "
") else() set(HtMLImageWithZoom="""{
Zoomed image with object borders
}" & ZoomBox & "
" & ZoomBox2 & """{
Zoomed Visual Image
}" & HintMap & """{
}" & Figuretext & "
") end() } proc ObjectFilter_wle_html(container _ inout) [hidden] { set(Htmlviewfactor=1) set(zoom=1) set(MainResultImageName="_results." & _spell.name & ".FilterImage_hidden") if(defined("VisualImage")) gamma(2.6,image=VisualImage) set(VisualImage_hidden=image) delete(image) set(MainResultImageName2="_results." & _spell.name & ".VisualImage_hidden") else() set(MainResultImageName2="_results." & _spell.name & ".FilterImage_hidden") end() CreateHintMap2Zooms_WLE(AttrTableTech,MainResultImageName,MainResultImageName,MainResultImageName2, zoom=zoom, width=HtmlviewFactor*FilterImage_hidden.width,bgcolor="#FFFFAA",zoomwfactor=3,zoomfactor=3, HTMLView_URL=HTMLView_URL,OrigImageWidth=FilterImage_hidden.width,OrigImageheight=FilterImage_hidden.height) if(!defined("VisualImage")) set(zoom=0) end() } proc ObjectFilter_wle_visual(container _ inout) [hidden] { set(MaxObjectToTable=500) set(FigureText="
Output objects
White: discarded objects.
Red, Yellow, Green, Blue, Violet: classified objects.
Number of objects before filters: " & ObjectsBeforeFilters & "
Number of objects after filters: " & ObjectsAfterFilters & "
") ObjectFilter_wle_html() ObjectFilter_wle_html_code() set(FilterImage=HtMLImageWithZoom) //set(FilterImage=" " & text1 & "") delete(list) WizardPushVar("FilterImage","visual","", Title="With white are marked the discarded objects, with red, blue,green, yellow and violet ones which passed the filters") if(objects.count>MaxObjectToTable) tablefilter(objectno