def __NbFoci(self): self.__boolFoci=True self.__image.killRoi() self.__image.setRoi(self.__contour) self.__ip=self.__image.getProcessor() rt=ResultsTable.getResultsTable() rt.reset() mf=MaximumFinder() mf.findMaxima(self.__ip, self.__noise, 0, MaximumFinder.LIST, True, False) self.__listMax[:]=[] #feret=self.getFercoord() #xc=feret[0]-((feret[0]-feret[2])/2.0) #yc=feret[1]-((feret[1]-feret[3])/2.0) #print xc, yc xc=self.getXC() yc=self.getYC() #print xc, yc for i in range(rt.getCounter()): x=int(rt.getValue("X", i)) y=int(rt.getValue("Y", i)) size=self.__localwand(x, y, self.__ip, self.__seuilPeaks, self.__peaksMethod, self.__light) coord=[(1, xc, x), (1, yc, y)] d=self.distMorph(coord,"Euclidean distance") d=( d / (self.getMaxF()/2) )*100 self.__listMax.append((x, y, size[0], size[1], size[2], size[3], size[4], d)) rt.reset()
def findCells(imp, rm, channel, noisetol, thresh): ''' Function for finding cells as local maxima and creating an ROI showing them imp: ImagePlus rm: the current ROI manager channel, int: the channel being processed (used for ROI name) noisetol, thresh, ints: noise tolerance and pixel value threshold for findMaxima returns the count ''' # set the channel imp.setC(channel) # find maxima ip = imp.getProcessor() mf = MaximumFinder() maxima = mf.findMaxima(ip, noisetol, thresh, MaximumFinder.SINGLE_POINTS, False, False) findmaximashow = ImagePlus("Found Maxima", maxima) findmaximashow.show() # an image of all the points maximaip = findmaximashow.getProcessor() maximahist = maximaip.getHistogram() cellCount = maximahist[255] if cellCount != 0: IJ.setRawThreshold(findmaximashow, 255, 255, "red") IJ.run(findmaximashow, "Create Selection", "") rm.addRoi(findmaximashow.getRoi() ) # a selection consisting of all the points # close maxima image if present if findmaximashow: findmaximashow.close() return cellCount
if output_type == 'Single_Points': output_type_param = mf.SINGLE_POINTS elif output_type == 'Maxima_Within_Tolerance': output_type_param = mf.IN_TOLERANCE elif output_type == 'Segmented_Particles': output_type_param = mf.SEGMENTED elif output_type == 'List': output_type_param = mf.LIST elif output_type == 'Count': output_type_param = mf.COUNT # Get a new byteProcessor with a normal (uninverted) LUT where # the marked points are set to 255 (Background 0). Pixels outside # of the roi of the input image_processor_copy are not set. No # output image is created for output types POINT_SELECTION, LIST # and COUNT. In these cases findMaxima returns null. byte_processor = mf.findMaxima( image_processor_copy, noise_tolerance, ImageProcessor.NO_THRESHOLD, output_type_param, exclude_edge_maxima, False ) # Invert the image or ROI. byte_processor.invert() if output_type == 'Segmented_Particles' and not light_background: # Invert the values in this image's LUT (indexed color model). byte_processor.invertLut() image_plus = ImagePlus( "output", byte_processor ) IJ.saveAs( image_plus, output_datatype, tmp_output_path ) except Exception, e: jython_utils.handle_error( error_log, str( e ) )
# by the tolerance. mf = MaximumFinder() if output_type == 'Single_Points': output_type_param = mf.SINGLE_POINTS elif output_type == 'Maxima_Within_Tolerance': output_type_param = mf.IN_TOLERANCE elif output_type == 'Segmented_Particles': output_type_param = mf.SEGMENTED elif output_type == 'List': output_type_param = mf.LIST elif output_type == 'Count': output_type_param = mf.COUNT # Get a new byteProcessor with a normal (uninverted) LUT where # the marked points are set to 255 (Background 0). Pixels outside # of the roi of the input image_processor_copy are not set. No # output image is created for output types POINT_SELECTION, LIST # and COUNT. In these cases findMaxima returns null. byte_processor = mf.findMaxima(image_processor_copy, noise_tolerance, ImageProcessor.NO_THRESHOLD, output_type_param, exclude_edge_maxima, False) # Invert the image or ROI. byte_processor.invert() if output_type == 'Segmented_Particles' and not light_background: # Invert the values in this image's LUT (indexed color model). byte_processor.invertLut() image_plus = ImagePlus("output", byte_processor) IJ.saveAs(image_plus, output_datatype, tmp_output_path) except Exception, e: jython_utils.handle_error(error_log, str(e))
def __fmaxfinder(self) : #stack = self.__impRes.getStack() self.__impD.killRoi() self.__impF.killRoi() stack = self.__impF.getStack() n_slices = stack.getSize() #newstack=ImageStack(self.__impRes.getWidth(), self.__impRes.getHeight()) newstack=ImageStack(self.__impF.getWidth(), self.__impF.getHeight()) noise = self.__display3.text for index in range(1,n_slices+1): IJ.selectWindow(self.__impF.getTitle()) self.__impF.setSlice(index) ip = self.__impF.getProcessor() mf=MaximumFinder() ipmax = mf.findMaxima(ip, int(noise), 0, 0, False, False) newstack.addSlice("", ipmax) newimage=ImagePlus("max points"+self.__name, newstack) newimage.show() newimage.updateAndDraw() listip = [] maxh=self.__impRes.getHeight() for roi in self.__cellsrois : straightener = Straightener() newimage.setSlice(roi[1]) newimage.setRoi(roi[0]) #listip.append(straightener.straighten(newimage, roi[0], int(self.__widthl))) listip.append(straightener.straighten(newimage, roi[0], maxh)) ipw=[ ip.getWidth() for ip in listip ] iph=[ ip.getHeight() for ip in listip ] maxw=max(ipw) maxh=max(iph) if self.__enlarge : resizelist = [ ip.resize(maxw, maxh, True) for ip in listip ] elif self.__alignC : resizelist = [] for ip in listip : tempip = ByteProcessor(maxw, maxh) tempip.copyBits(ip, 0, 0, Blitter.COPY) resizelist.append(tempip) else : resizelist = [] for ip in listip : tempip = ByteProcessor(maxw, maxh) tempip.copyBits(ip, 0, 0, Blitter.COPY) resizelist.append(tempip) ims = ImageStack(maxw, maxh) #for ip in resizelist : ims.addSlice("", ip) for i in range(len(resizelist)) : ims.addSlice(self.__labels[i], resizelist[i]) self.__impMax = ImagePlus(self.__name+"-max", ims) self.__impMax.show() stack = self.__impMax.getStack() # get the stack within the ImagePlus n_slices = stack.getSize() for index in range(1, n_slices+1): self.__impMax.killRoi() self.__impMax.setSlice(index) roi = self.__listrois[index-1] if self.__sens[index-1]<0 : self.__impMax.setRoi(roi) ip1 = self.__impMax.getProcessor() ip1.flipHorizontal() self.__impMax.killRoi() self.__impMax.updateAndDraw() ip = self.__impMax.getProcessor() for i in range(ip.getWidth()*ip.getHeight()) : if ip.getf(i) > 0 : ip.setf(i, 255) #else : ip.setf(i, 0) IJ.run(self.__impMax, "8-bit", "") IJ.run(self.__impMax, "Options...", "iterations=2 count=1 black edm=Overwrite do=Close stack") IJ.run(self.__impMax, "Ultimate Points", "stack") self.__impMax.updateAndDraw()
rt.reset() # supposed to reset the results table postReset = rt.getCounter() print "After resetting there are " + str(postReset) + " results" IJ.run("Select None") print "Using the IJ.run method with no threshold, I found " + str( CountMethod1) + " maxima." # ---- METHOD 2: API findMaxima WITH THRESHOLD AND SINGLE POINTS # findMaxima(ImageProcessor ip, double tolerance, double threshold, int outputType, boolean excludeOnEdges, boolean isEDM) # source: https://github.com/imagej/ImageJA/blob/8e283502055d25b9f0456f4aad95afa30a649d45/src/main/java/ij/plugin/filter/MaximumFinder.java # note LIST produces list of coors, SINGLE POINTS produces a bunch of points that are shown by the code below. # POINT_SELECTION is supposed to give just that but can't figure out how to get it in the manager # https://stackoverflow.com/questions/26526269/image-analysis-finding-proteins-in-an-image # https://github.com/bgruening/galaxytools/blob/18b441b263846cece9c5527cab0de66a54ecba3a/tools/image_processing/imagej2/imagej2_find_maxima/jython_script.py maxima = mf.findMaxima(ip, 100.0, THRESH, MaximumFinder.SINGLE_POINTS, False, False) findmaximashow = ImagePlus("Found Maxima", maxima) findmaximashow.show() # an image of all the points maximaip = findmaximashow.getProcessor() maximahist = maximaip.getHistogram() CountMethod2 = maximahist[255] print "Using the findMaxima method with a threshold of " + str( THRESH) + ", I found " + str(CountMethod2) + " maxima." IJ.setRawThreshold(findmaximashow, 255, 255, "red") IJ.run(findmaximashow, "Create Selection", "") rm.addRoi(findmaximashow.getRoi()) rm.rename(1, "Maxima with threshold") # ---- METHOD 3-4: API getMaxima WITH THE POINTS COUNTED OR ADDED TO THE RESULTS TABLE