예제 #1
0
def preprocess_slices_giv_im(image_num,file_inpath,file_outpath):

	imp = IJ.openImage(file_inpath)
	file_names,rows = getLabels()
	stack = imp.getImageStack()
	stack2 = ImageStack(imp.width,imp.height)
	 
	for j in range(imp.getNSlices()):
		if rows[j][image_num]== '0':
			ip = stack.getProcessor(j+1)
			NormalizeLocalContrast.run(ip, 341, 326, 4, True, True)
			imagep = ImagePlus("imp",ip)
			IJ.run(imagep, "Non-local Means Denoising", "sigma=15 smoothing_factor=1 slice")
			imagep.setRoi(2,0,336,320);
			IJ.run(imagep, "Level Sets", "method=[Active Contours] use_level_sets grey_value_threshold=50 distance_threshold=0.50 advection=2.20 propagation=1 curvature=1 grayscale=30 convergence=0.0025 region=inside")
			fimp = IJ.getImage()
			#fip  = fimp.getProcessor()
			fimp = removeSmallCCs(fimp)
			fip  = fimp.getProcessor()
			stack2.addSlice(fip)
			print("process")
		
		else:
			ip = stack.getProcessor(j+1)
			stack2.addSlice(ip)


	final_imp = ImagePlus("image",stack2)
	output = "nrrd=["+file_outpath+"]"
	IJ.run(final_imp, "Nrrd ... ", output)
def executeFilter(ip):
    """ Given an ImageProcessor ip and a dictionary of parameters, filter the ip,
      and return the same or a new ImageProcessor of the same dimensions and type. """
    blockRadiusX = params["blockRadiusX"]
    blockRadiusY = params["blockRadiusY"]
    stds = params["stds"]
    center = params["center"]
    stretch = params["stretch"]
    NormalizeLocalContrast.run(ip, blockRadiusX, blockRadiusY, stds, center,
                               stretch)
    return ip
예제 #3
0
 def getProcessor(self, n):
     # Load the image at index n
     filepath = os.path.join(self.getDirectory(), self.getFileName(n))
     imp = IJ.openImage(filepath)
     # Filter it:
     ip = imp.getProcessor()
     blockRadiusX = self.params["blockRadiusX"]
     blockRadiusY = self.params["blockRadiusY"]
     stds = self.params["stds"]
     center = self.params["center"]
     stretch = self.params["stretch"]
     NormalizeLocalContrast.run(ip, blockRadiusX, blockRadiusY, stds, center, stretch)
     return ip
예제 #4
0
def asNormalizedUnsignedByteArrayImg(blockRadius, stds, center, stretch, imp):
    sp = imp.getProcessor()  # ShortProcessor
    NormalizeLocalContrast().run(sp, blockRadius, blockRadius, stds, center,
                                 stretch)
    return ArrayImgs.unsignedBytes(
        sp.convertToByte(True).getPixels(),
        [sp.getWidth(), sp.getHeight()])
예제 #5
0
def normalizeContrast(imp):
  # The width and height of the box centered at every pixel:
  blockRadiusX = 200 # in pixels
  blockRadiusY = 200
  # The number of standard deviations to expand to
  stds = 2
  # Whether to expand from the median value of the box or the pixel's value
  center = True
  # Whether to stretch the expanded values to the pixel depth of the image
  # e.g. between 0 and 255 for 8-bit images, or e.g. between 0 and 65536, etc.
  stretch = True
  # Duplicate the ImageProcessor
  copy_ip = imp.getProcessor().duplicate()
  # Apply contrast normalization to the copy
  NormalizeLocalContrast().run(copy_ip, 200, 200, stds, center, stretch)
  # Return as new image
  return ImagePlus(imp.getTitle(), copy_ip)
def normalizeContrast(imp):
    # slide box 크기
    blockRadiusX = 200 # pixel 단위
    blockRadiusY = 200
    # The number of standard deviations to expand to  
    stds = 2
    # Whether to expand from the median value of the box or the pixel's value
    center = True
    # Whether to stretch the expanded values to the pixel depth of the image  
    # e.g. between 0 and 255 for 8-bit images, or e.g. between 0 and 65536, etc.  
    stretch = True
    
    # Duplicate the ImageProcessor
    copy_ip = imp.getProcessor().duplicate()
    # Contrast Normalization을 copy에 적용
    NormalizeLocalContrast().run(copy_ip,  blockRadiusX, blockRadiusY, stds, center, stretch)
    # Return as new image
    return ImagePlus(imp.getTitle(), copy_ip)
# Read the dimensions from the first image  
first_path = os.path.join(sourceDir, tiffImageFilenames(sourceDir).next())  
width, height = dimensionsOf(first_path)  

# Create the VirtualStack without a specific ColorModel  
# (which will be set much later upon loading any slice)  
vstack = VirtualStack(width, height, None, sourceDir)  

# Add all TIFF images in sourceDir as slices in vstack  
for filename in tiffImageFilenames(sourceDir):  
    vstack.addSlice(filename)  
  
# Visualize the VirtualStack  
imp = ImagePlus("virtual stack of images in " + os.path.basename(sourceDir), vstack)  
# imp.show()  

from mpicbg.ij.plugin import NormalizeLocalContrast
from ij.io import FileSaver

# slice마다 process 후 targetDir에 save
for i in xrange(0, vstack.size()):
    ip = vstack.getProcessor(i+1)   # slice list는 1부터 시작 (1-based listing)
    # NormalizeLocalContrast plugin을 ImageProcessor에 적용
    NormalizeLocalContrast.run(ip, 200, 200, 3, True, True)
    # 결과 저장
    name = vstack.getFileName(i+1)
    if not name.lower().endswith(".tif"):
        name += ".tif"
    FileSaver(ImagePlus(name, ip)).saveAsTiff(os.path.join(targetDir, name))
예제 #8
0
def normLocalContrast(im, x, y, stdev, center, stretch):
	NormalizeLocalContrast().run(im.getProcessor(), x, y, stdev, center, stretch) # something like repaint needed ?
	return im