def poreDetectionUV(inputImp, inputDataset, inputRoi, ops, data, display, detectionParameters): title = inputImp.getTitle() title=title.replace('UV', 'SD') print title #trueColorImp= WindowManager.getImage(title) #print type( trueColorImp) # calculate are of roi stats=inputImp.getStatistics() inputRoiArea=stats.area print inputRoi # get the bounding box of the active roi inputRec = inputRoi.getBounds() x1=long(inputRec.getX()) y1=long(inputRec.getY()) x2=x1+long(inputRec.getWidth())-1 y2=y1+long(inputRec.getHeight())-1 print x1 print y1 print x2 print y2 # crop the roi interval=FinalInterval( array([x1, y1 ,0], 'l'), array([x2, y2, 2], 'l') ) cropped=ops.crop(interval, None, inputDataset.getImgPlus() ) datacropped=data.create(cropped) display.createDisplay("cropped", datacropped) croppedPlus=IJ.getImage() duplicator=Duplicator() substackMaker=SubstackMaker() # duplicate the roi duplicate=duplicator.run(croppedPlus) #duplicate.show() # convert duplicate of roi to HSB and get brightness IJ.run(duplicate, "HSB Stack", ""); brightnessPlus=substackMaker.makeSubstack(duplicate, "3-3") brightness=ImgPlus(ImageJFunctions.wrapByte(brightnessPlus)) brightnessPlus.setTitle("Brightness") #brightnessPlus.show() # make another duplicate, split channels and get red duplicate=duplicator.run(croppedPlus) channels=ChannelSplitter().split(duplicate) redPlus=channels[0] red=ImgPlus(ImageJFunctions.wrapByte(redPlus)) redPlus.show() # convert to lab IJ.run(croppedPlus, "Color Transformer", "colour=Lab") IJ.selectWindow('Lab') labPlus=IJ.getImage() # get the A channel APlus=substackMaker.makeSubstack(labPlus, "2-2") APlus.setTitle('A') APlus.show() APlus.getProcessor().resetMinAndMax() APlus.updateAndDraw() AThresholded=threshold(APlus, -10, 50) # get the B channel BPlus=substackMaker.makeSubstack(labPlus, "3-3") BPlus.setTitle('B') BPlus.show() BPlus.getProcessor().resetMinAndMax() BPlus.updateAndDraw() BThresholded=threshold(BPlus, -10, 50) # AND the Athreshold and Bthreshold to get a map of the red pixels ic = ImageCalculator(); redMask = ic.run("AND create", AThresholded, BThresholded); IJ.run(redMask, "Divide...", "value=255"); #redMask.show() labPlus.close() # threshold the spots from the red channel thresholdedred=SpotDetectionGray(red, data, display, ops, False) display.createDisplay("thresholdedred", data.create(thresholdedred)) impthresholdedred = ImageJFunctions.wrap(thresholdedred, "wrapped") # threshold the spots from the brightness channel thresholded=SpotDetectionGray(brightness, data, display, ops, False) display.createDisplay("thresholded", data.create(thresholded)) impthresholded=ImageJFunctions.wrap(thresholded, "wrapped") # or the thresholding results from red and brightness channel impthresholded = ic.run("OR create", impthresholded, impthresholdedred); # convert to mask Prefs.blackBackground = True IJ.run(impthresholded, "Convert to Mask", "") # clear the region outside the roi clone=inputRoi.clone() clone.setLocation(0,0) Utility.clearOutsideRoi(impthresholded, clone) # create a hidden roi manager roim = RoiManager(True) # count the particlesimp.getProcessor().setColor(Color.green) countParticles(impthresholded, roim, detectionParameters.minSize, detectionParameters.maxSize, detectionParameters.minCircularity, detectionParameters.maxCircularity) # define a function to determine the percentage of pixels that are foreground in a binary image # inputs: # imp: binary image, 0=background, 1=foreground # roi: an roi def isRed(imp, roi): stats = imp.getStatistics() if (stats.mean>detectionParameters.redPercentage): return True else: return False def notRed(imp, roi): stats = imp.getStatistics() if (stats.mean>detectionParameters.redPercentage): return False else: return True allList=[] for roi in roim.getRoisAsArray(): allList.append(roi.clone()) # count particles that are red redList=CountParticles.filterParticlesWithFunction(redMask, allList, isRed) # count particles that are red blueList=CountParticles.filterParticlesWithFunction(redMask, allList, notRed) print "Total particles: "+str(len(allList)) print "Filtered particles: "+str(len(redList)) # for each roi add the offset such that the roi is positioned in the correct location for the # original image [roi.setLocation(roi.getXBase()+x1, roi.getYBase()+y1) for roi in allList] # create an overlay and add the rois overlay1=Overlay() inputRoi.setStrokeColor(Color.green) overlay1.add(inputRoi) [CountParticles.addParticleToOverlay(roi, overlay1, Color.red) for roi in redList] [CountParticles.addParticleToOverlay(roi, overlay1, Color.cyan) for roi in blueList] def drawAllRoisOnImage(imp, mainRoi, redList, blueList): imp.getProcessor().setColor(Color.green) IJ.run(imp, "Line Width...", "line=3"); imp.getProcessor().draw(inputRoi) imp.updateAndDraw() IJ.run(imp, "Line Width...", "line=1"); [CountParticles.drawParticleOnImage(imp, roi, Color.magenta) for roi in redList] [CountParticles.drawParticleOnImage(imp, roi, Color.green) for roi in blueList] imp.updateAndDraw() drawAllRoisOnImage(inputImp, inputRoi, redList, blueList) #drawAllRoisOnImage(trueColorImp, inputRoi, redList, blueList) # draw overlay #inputImp.setOverlay(overlay1) #inputImp.updateAndDraw() statsdict=CountParticles.calculateParticleStats(APlus, BPlus, redMask, roim.getRoisAsArray()) print inputRoiArea areas=statsdict['Areas'] poreArea=0 for area in areas: poreArea=poreArea+area ATotal=0 ALevels=statsdict['ALevel'] for A in ALevels: ATotal=ATotal+A AAverage=ATotal/len(ALevels) BTotal=0 BLevels=statsdict['BLevel'] for B in BLevels: BTotal=BTotal+B BAverage=BTotal/len(BLevels) redTotal=0 redPercentages=statsdict['redPercentage'] for red in redPercentages: redTotal=redTotal+red redAverage=redTotal/len(redPercentages) pixwidth=inputImp.getCalibration().pixelWidth inputRoiArea=inputRoiArea/(pixwidth*pixwidth) print str(len(allList))+" "+str(len(redList))+" "+str(len(blueList))+" "+str(poreArea/inputRoiArea)+" "+str(redAverage)
script_path = os.getcwd() if "Fiji.app" in script_path: ss = script_path.split("Fiji.app") final_folder = "marcksl1 shape prescreener" script_path = os.path.join(ss[0], "Fiji.app", "plugins", "Scripts", "Plugins", final_folder) sys.path.insert(0, os.path.join(script_path, 'modules')) sys.path.insert(0, os.path.join(script_path, 'classes')) from UpdateRoiImageListener import UpdateRoiImageListener # angle method max_r_pix = 60 min_r_pix = 10 split_chs = ChannelSplitter().split(imp) mch_imp = split_chs[0] egfp_imp = split_chs[1] egfp_imp_disp = Duplicator().run(egfp_imp) cl_imp = split_chs[2] #egfp_imp.show(); centres = [] projected_im_pix = [] ring_rois = [] unzip_axis = [] roi_stack = IJ.createImage("rois", egfp_imp.getWidth(), egfp_imp.getHeight(), egfp_imp.getNSlices(), 16) #roi_stack.show(); for zidx in range(cl_imp.getNSlices()):
# Check if folders are there or not if not os.path.exists(saveDir): os.mkdir(saveDir) # set up options for import opts = ImporterOptions() opts.setId(filename) opts.setUngroupFiles(True) # set up import process process = ImportProcess(opts) process.execute() nseries = process.getSeriesCount() # Channel Splitter Definition splitter = ChannelSplitter() # reader belonging to the import process reader = process.getReader() # reader external to the import process impReader = ImagePlusReader(process) # loop through all series in file for i in range(0, nseries): print "%d/%d %s" % (i+1, nseries, process.getSeriesLabel(i)[10:]) # activate series (same as checkbox in GUI) opts.setSeriesOn(i,True) # point import process reader to this series
from ij import IJ, ImagePlus # Fetch an RGB image stack imp_rgb = IJ.getImage() # IJ.openImage("http://imagej.nih.gov/ij/images/flybrain.zip") # Define a threshold for the red channel: any values at or above # in the green channel will be placed into a new image threshold = 119 # Example 1: with ImageCalculator from ij.process import ImageProcessor from ij.plugin import ChannelSplitter, ImageCalculator # Split color channels red, green, blue = ChannelSplitter().split(imp_rgb) # 3 ImagePlus # Set threshold for each slice for index in xrange(1, red.getNSlices() + 1): bp = red.getStack().getProcessor(index) #bp.setThreshold(threshold, 255, ImageProcessor.BLACK_AND_WHITE_LUT) bp.threshold(threshold) # mask is 0, background is 255 # Apply threshold: convert each slice to a mask (only 0 or 255 pixel values) #IJ.run(red, "Convert to Mask", "method=Default background=Dark black") red.show() green_under_red_mask = ImageCalculator().run("and create stack", red, green) green_under_red_mask.show() """ # Example 2: with ImgLib2 LoopBuilder
def main(): #print (sys.version_info) # debug #print(sys.path) # debug data_root = r'C:\Users\dougk\Desktop\test' # debug output_root = r'C:\Users\dougk\Desktop\test' #debug #default_directory = r'C:\\Users\\Doug\\Desktop\\test'; #data_root, output_root = file_location_chooser(default_directory); if (data_root is None) or (output_root is None): raise IOError("File location dialogs cancelled!") timestamp = datetime.strftime(datetime.now(), "%Y-%m-%d %H.%M.%S") output_path = os.path.join(output_root, (timestamp + " output")) for file_path in filterByFileType(os.listdir(data_root), '.tif'): subfolder_name = os.path.splitext(file_path)[0] output_subfolder = os.path.join(output_path, subfolder_name) print(output_subfolder) os.makedirs(output_subfolder) imps = bf.openImagePlus(os.path.join(data_root, file_path)) imp = imps[0] imp.show() h = imp.height w = imp.width slices = imp.getNSlices() channels = imp.getNChannels() frames = imp.getNFrames() # rotation step - since using multiples of 90, TransformJ.Turn is more efficient IJ.run("Enhance Contrast", "saturated=0.35") angleZ = 1 while ((angleZ % 90) > 0): gd = GenericDialog("Rotate?") gd.addMessage( "Define rotation angle - increments of 90. Apical at top") gd.addNumericField("Rotation angle", 0, 0) gd.showDialog() angleZ = int(gd.getNextNumber()) if (angleZ > 1): IJ.run("TransformJ Turn", "z-angle=" + str(angleZ) + " y-angle=0 x-angle=0") imp.close() imp = WindowManager.getCurrentImage() imp.setTitle(file_path) # trim time series IJ.run("Enhance Contrast", "saturated=0.35") imp.setDisplayMode(IJ.COLOR) WaitForUserDialog( "Scroll to the first frame of the period of interest and click OK" ).show() start_frame = imp.getT() WaitForUserDialog( "Scroll to the last frame of the period of interest and click OK" ).show() end_frame = imp.getT() trim_imp = Duplicator().run(imp, 1, channels, 1, slices, start_frame, end_frame) imp.close() trim_imp.show() dup_imp = Duplicator().run(trim_imp) # create images to process and find bounds for dup_imps = ChannelSplitter().split(dup_imp) myo_imp = dup_imps[1] mem_imp = dup_imps[0] FileSaver(myo_imp).saveAsTiffStack( os.path.join(output_subfolder, "myosin_channel.tif")) FileSaver(mem_imp).saveAsTiffStack( os.path.join(output_subfolder, "membrane_channel.tif")) # set basal bounds myo_imp.show() ImageConverter(myo_imp).convertToGray8() frames = myo_imp.getNFrames() gb = GaussianBlur() for fridx in range(0, frames): myo_imp.setSliceWithoutUpdate(fridx + 1) ip = myo_imp.getProcessor() gb.blurGaussian(ip, 5.0, 1.0, 0.02) # assymmetrical Gaussian IJ.run(myo_imp, "Convert to Mask", "method=Otsu background=Dark calculate") IJ.run("Despeckle", "stack") title = myo_imp.getTitle() # assume that first frame is good quality image... basal_edges = find_basal_edges(myo_imp) #myo_imp.hide() mem_imp.hide() # draw some edges for checking roim = RoiManager() xs = [x for x in range(1, trim_imp.getWidth() + 1)] trim_imp.show() for fridx in range(0, myo_imp.getNFrames()): trim_imp.setPosition(2, 1, fridx + 1) IJ.run("Enhance Contrast", "saturated=0.35") roi = PolygonRoi(xs, basal_edges[fridx], Roi.POLYLINE) trim_imp.setRoi(roi) roim.addRoi(roi)
def do_angular_projection(imp, max_r_pix=60, min_r_pix=10, generate_roi_stack=True): """perform ray-based projection of vessel wall, c.f. ICY TubeSkinner (Lancino 2018)""" Prefs.blackBackground = True print("do angular projection input imp = " + str(imp)) split_chs = ChannelSplitter().split(imp) mch_imp = split_chs[0] IJ.setAutoThreshold(mch_imp, "IsoData dark stack") egfp_imp = split_chs[1] proj_imp = Duplicator().run(egfp_imp) cl_imp = split_chs[2] if generate_roi_stack: egfp_imp_disp = Duplicator().run(egfp_imp) roi_stack = IJ.createImage("rois", egfp_imp.getWidth(), egfp_imp.getHeight(), egfp_imp.getNSlices(), 16) centres = [] projected_im_pix = [] ring_rois = [] for zidx in range(cl_imp.getNSlices()): if ((zidx + 1) % 100) == 0: print("Progress = " + str(round(100 * (float(zidx + 1) / cl_imp.getNSlices())))) projected_im_row = [] proj_imp.setZ(zidx + 1) mch_imp.setZ(zidx + 1) bp = mch_imp.createThresholdMask() bp.dilate() bp.erode() bp.erode() bp.erode() mask_imp = ImagePlus("mask", bp) IJ.run(mask_imp, "Create Selection", "") roi = mask_imp.getRoi() proj_imp.setRoi(roi) IJ.run(proj_imp, "Set...", "value=0 slice") IJ.run(proj_imp, "Make Inverse", "") roi = proj_imp.getRoi() centre = (roi.getStatistics().xCentroid, roi.getStatistics().yCentroid) centres.append(centre) ring_roi_xs = [] ring_roi_ys = [] for theta in range(360): pt1 = (centre[0] + min_r_pix * math.cos(math.radians(theta)), centre[1] + min_r_pix * math.sin(math.radians(theta))) pt2 = (centre[0] + max_r_pix * math.cos(math.radians(theta)), centre[1] + max_r_pix * math.sin(math.radians(theta))) roi = Line(pt1[0], pt1[1], pt2[0], pt2[1]) proj_imp.setRoi(roi) profile = roi.getPixels() projected_im_row.append(max(profile)) try: ring_roi_xs.append(roi.getContainedPoints()[profile.index( max(profile))].x) except IndexError: ring_roi_xs.append(pt2[0]) try: ring_roi_ys.append(roi.getContainedPoints()[profile.index( max(profile))].y) except IndexError: ring_roi_ys.append(pt2[1]) proj_imp.killRoi() ring_roi = PolygonRoi(ring_roi_xs, ring_roi_ys, Roi.FREELINE) ring_rois.append(ring_roi) if generate_roi_stack: roi_stack.setZ(zidx + 1) roi_stack.setRoi(ring_roi) IJ.run(roi_stack, "Line to Area", "") IJ.run( roi_stack, "Set...", "value=" + str(roi_stack.getProcessor().maxValue()) + " slice") #egfp_imp.setRoi(ring_roi); projected_im_pix.append(projected_im_row) # for ch in split_chs: # ch.close(); out_imp = ImagePlus( "projected", FloatProcessor([list(x) for x in zip(*projected_im_pix)])) if generate_roi_stack: roi_stack.show() egfp_imp_disp.show() # merge? else: roi_stack = None return out_imp, roi_stack, ring_rois, centres
def do_slicewise_unwrap(imp): """at each position along the lumen axis, get a shell from around the lumen and take the maximum in the cell channel""" split_chs = ChannelSplitter().split(imp) mch_imp = split_chs[0] egfp_imp = split_chs[1] cl_imp = split_chs[2] mch_imp.show() egfp_imp.show() IJ.setAutoThreshold(mch_imp, "IsoData light stack") centres = [] for zidx in range(200, 202): print(zidx) mch_imp.setZ(zidx + 1) cl_imp.setZ(zidx + 1) ip = cl_imp.getProcessor() maxpt = MaximumFinder().getMaxima(ip, 10, True) centre = (maxpt.xpoints[0], maxpt.ypoints[0]) centres.append(centre) bp = mch_imp.createThresholdMask() bp.erode() bp.dilate() mask_imp = ImagePlus("mask", bp) IJ.run(mask_imp, "Create Selection", "") roi = mask_imp.getRoi() print([(x, y) for x, y in zip(roi.getInterpolatedPolygon().xpoints, roi.getPolygon().ypoints)]) mask_imp.show() cl_imp.close() #Prefs.blackBackground = True; #out_imp, _, ring_rois, centres = do_angular_projection(imp, generate_roi_stack=True); #IJ.setAutoThreshold(out_imp, "Intermodes dark"); #threshold_val = out_imp.getProcessor().getMinThreshold(); #unwrapped_projection_imp, unwrap_axis = twist_and_unwrap(out_imp); #r_imp, mask_imp = generate_r_image(out_imp, ring_rois, centres, unwrap_axis, threshold_val); #r_imp.show(); #out_imp.close(); #unwrapped_projection_imp.show(); #area, aspect_ratio = calculate_area_and_aspect_ratio(r_imp, mask_imp, 0.108333); #print("A = " + str(area)); #print("Aspect ratio = " + str(aspect_ratio)); # #test_path = "C:\\Users\\dougk\\Desktop\\tile_imp_test.tif"; #tile_imp = IJ.openImage(test_path); #tile_imp.show(); #IJ.setTool("freeline"); #WaitForUserDialog("draw line").show(); #roi = tile_imp.getRoi(); #unwrap_poly = roi.getPolygon(); #unwrap_poly_xs = [x for x in unwrap_poly.xpoints]; #unwrap_poly_ys = [y for y in unwrap_poly.ypoints]; ## extend to the top and bottom of the image: #unwrap_poly_xs.insert(0, unwrap_poly_xs[0]); #unwrap_poly_xs.append(unwrap_poly_xs[-1]) #if unwrap_poly_ys[0] < unwrap_poly_ys[-1]: # unwrap_poly_ys.insert(0, 1); # unwrap_poly_ys.append(tile_imp.getHeight()); #else: # unwrap_poly_ys.insert(0, tile_imp.getHeight()); # unwrap_poly_ys.append(1); #unwrap_axis = [(x, y) for (x, y) in zip(unwrap_poly_xs, unwrap_poly_ys)]; #out_imp = do_unwrap(tile_imp, unwrap_axis)
from ij.gui import WaitForUserDialog, Roi, PolygonRoi from ij.plugin import ChannelSplitter, Straightener, ZProjector # run on imp containing result of tubefitter + IJ.run(imp, "Reslice [/]...", "output=1.000 start=Top avoid") + spline-fitted # manual roi copied from z-projected version of this resliced image (add roi from z-proj to ROI manager, then add # to resliced image) imp.killRoi(); IJ.run(imp, "Reslice [/]...", "output=1.000 start=Top avoid"); rot_imp = IJ.getImage(); crop_roi = Roi(10, 0, rot_imp.getWidth()-20, rot_imp.getHeight()); rot_imp.setRoi(crop_roi); rot_imp.crop(); rot_imp.show(); WaitForUserDialog("pause").show(); split_ch = ChannelSplitter().split(rot_imp); mch_imp = split_ch[0]; egfp_imp = split_ch[1]; roi_imp = split_ch[2]; zproj_imp = ZProjector.run(roi_imp, "max"); IJ.setRawThreshold(zproj_imp, 33153, 65535, None); IJ.run(zproj_imp, "Make Binary", "") zproj_imp.show(); raise error; IJ.run(zproj_imp, "Skeletonize", ""); IJ.run(zproj_imp, "Create Selection", ""); roi = zproj_imp.getRoi(); floatpoly = roi.getContainedFloatPoints(); roi = PolygonRoi(floatpoly, Roi.FREELINE); zproj_imp.setRoi(roi); WaitForUserDialog("pause").show();
parameters = {} parameters['avgI_low'] = 0.25 parameters['avgI_high'] = 0.65 parameters['cellsigma'] = 4 parameters['cellmethod'] = 'Triangle' parameters['cellsize'] = '10000-5000000' parameters['cellcircularity'] = '0.20-1.00' parameters['nucsigma'] = 4 parameters['nucmethod'] = 'Otsu' parameters['nucsize'] = '3500-10000' parameters['nuccircularity'] = '0.5-1.00' parameters['test'] = 0 #Class constructors rm = RoiManager() cs = ChannelSplitter() rmi = rm.getInstance() #Input and output directories inputPath = str(inputPath) outputPath = str(outputPath) imagelist = [ f for f in os.listdir(os.path.join(inputPath)) if f.lower()[0].isalnum() ] for sample in imagelist: rmi.reset() IJ.run('Close All') sample_label = sample.split('.')[0] outputFile = os.path.join(outputPath, sample_label + '.zip')
def poreDetectionUV(inputImp, inputDataset, inputRoi, ops, data, display, detectionParameters): # set calibration detectionParameters.setCalibration(inputImp) # calculate area of roi stats = inputImp.getStatistics() inputRoiArea = stats.area # get the bounding box of the active roi inputRec = inputRoi.getBounds() x1 = long(inputRec.getX()) y1 = long(inputRec.getY()) x2 = x1 + long(inputRec.getWidth()) - 1 y2 = y1 + long(inputRec.getHeight()) - 1 # crop the roi interval = FinalInterval(array([x1, y1, 0], 'l'), array([x2, y2, 2], 'l')) #cropped=ops.image().crop(interval, None, inputDataset.getImgPlus() ) cropped = ops.image().crop(inputDataset.getImgPlus(), interval) datacropped = data.create(cropped) display.createDisplay("cropped", datacropped) croppedPlus = IJ.getImage() # instantiate the duplicator and the substackmaker classes duplicator = Duplicator() substackMaker = SubstackMaker() # duplicate the roi duplicate = duplicator.run(croppedPlus) # convert duplicate of roi to HSB and get brightness IJ.run(duplicate, "HSB Stack", "") brightnessPlus = substackMaker.makeSubstack(duplicate, "3-3") brightness = ImgPlus(ImageJFunctions.wrapByte(brightnessPlus)) brightnessPlus.setTitle("Brightness") #brightnessPlus.show() # make another duplicate, split channels and get red duplicate = duplicator.run(croppedPlus) channels = ChannelSplitter().split(duplicate) redPlus = channels[0] red = ImgPlus(ImageJFunctions.wrapByte(redPlus)) # convert to lab IJ.run(croppedPlus, "Color Transformer", "colour=Lab") IJ.selectWindow('Lab') labPlus = IJ.getImage() croppedPlus.changes = False croppedPlus.close() # get the A channel APlus = substackMaker.makeSubstack(labPlus, "2-2") APlus.setTitle('A') #APlus.show() APlus.getProcessor().resetMinAndMax() #APlus.updateAndDraw() AThresholded = threshold(APlus, -10, 50) # get the B channel BPlus = substackMaker.makeSubstack(labPlus, "3-3") BPlus.setTitle('B') #BPlus.show() BPlus.getProcessor().resetMinAndMax() #BPlus.updateAndDraw() BThresholded = threshold(BPlus, -10, 50) # AND the Athreshold and Bthreshold to get a map of the red pixels ic = ImageCalculator() redMask = ic.run("AND create", AThresholded, BThresholded) IJ.run(redMask, "Divide...", "value=255") labPlus.close() fast = True # threshold the spots from the red channel if (fast == False): thresholdedred = SpotDetectionGray(red, data, display, ops, "triangle") impthresholdedred = ImageJFunctions.wrap(thresholdedred, "wrapped") else: impthresholdedred = SpotDetection2(redPlus) # threshold the spots from the brightness channel if (fast == False): thresholded = SpotDetectionGray(brightness, data, display, ops, "triangle") impthresholded = ImageJFunctions.wrap(thresholded, "wrapped") else: impthresholded = SpotDetection2(brightnessPlus) # or the thresholding results from red and brightness channel impthresholded = ic.run("OR create", impthresholded, impthresholdedred) roim = RoiManager(True) # convert to mask Prefs.blackBackground = True IJ.run(impthresholded, "Convert to Mask", "") def isRed(imp, roi): stats = imp.getStatistics() if (stats.mean > detectionParameters.porphyrinRedPercentage): return True else: return False def notRed(imp, roi): stats = imp.getStatistics() if (stats.mean > detectionParameters.porphyrinRedPercentage): return False else: return True roiClone = inputRoi.clone() roiClone.setLocation(0, 0) Utility.clearOutsideRoi(impthresholded, roiClone) impthresholded.show() countParticles(impthresholded, roim, detectionParameters.porphyrinMinSize, detectionParameters.porphyrinMaxSize, \ detectionParameters.porphyrinMinCircularity, detectionParameters.porphyrinMaxCircularity) uvPoreList = [] for roi in roim.getRoisAsArray(): uvPoreList.append(roi.clone()) #allList=uvPoreList+closedPoresList+openPoresList # count particles that are porphyrins (red) porphyrinList = CountParticles.filterParticlesWithFunction( redMask, uvPoreList, isRed) # count particles that are visible on uv but not porphyrins sebumList = CountParticles.filterParticlesWithFunction( redMask, uvPoreList, notRed) # for each roi add the offset such that the roi is positioned in the correct location for the # original image [ roi.setLocation(roi.getXBase() + x1, roi.getYBase() + y1) for roi in uvPoreList ] # draw the ROIs on to the image inputImp.getProcessor().setColor(Color.green) IJ.run(inputImp, "Line Width...", "line=3") inputImp.getProcessor().draw(inputRoi) IJ.run(inputImp, "Line Width...", "line=1") [ CountParticles.drawParticleOnImage(inputImp, roi, Color.magenta) for roi in porphyrinList ] [ CountParticles.drawParticleOnImage(inputImp, roi, Color.green) for roi in sebumList ] inputImp.updateAndDraw() # calculate stats for the UV visible particles detectionParameters.setCalibration(APlus) statsDictUV = CountParticles.calculateParticleStatsUV( APlus, BPlus, redMask, roim.getRoisAsArray()) totalUVPoreArea = 0 for area in statsDictUV['Areas']: totalUVPoreArea = totalUVPoreArea + area averageUVPoreArea = totalUVPoreArea / len(statsDictUV['Areas']) poreDiameter = 0 for diameter in statsDictUV['Diameters']: poreDiameter = poreDiameter + diameter poreDiameter = poreDiameter / len(statsDictUV['Diameters']) redTotal = 0 for red in statsDictUV['redPercentage']: redTotal = redTotal + red redAverage = redTotal / len(statsDictUV['redPercentage']) statslist = [len(porphyrinList), 100 * redAverage] statsheader = [Messages.Porphyrins, Messages.PercentageRedPixels] print("Roi Area: " + str(inputRoiArea)) print("Total Pore Area: " + str(totalUVPoreArea)) print("Average Pore Area: " + str(averageUVPoreArea)) print str(len(uvPoreList)) + " " + str(len(porphyrinList)) + " " + str( len(sebumList)) + " " + str( 100 * totalUVPoreArea / inputRoiArea) + " " + str(100 * redAverage) print "cp min circularity" + str( detectionParameters.closedPoresMinCircularity) + ":" + str( detectionParameters.closedPoresMinSize) # close the thresholded image impthresholded.changes = False impthresholded.close() return uvPoreList, statslist, statsheader