Exemple #1
0
def resizeAndSave(filePaths, l):
	while l.get() < min(len(filePaths), currentWrittenLayer + nTilesAtATime + 1) :
		k = l.getAndIncrement()
		if k < min(len(filePaths), currentWrittenLayer + nTilesAtATime):

			filePath = filePaths[k]
			
			imageName = os.path.basename(filePath)
			resizedImageName = os.path.splitext(imageName)[0] + '_resized_' + factorString + os.path.splitext(imageName)[1]
			
			imageFolderName = os.path.basename(os.path.dirname(filePath))
			
			resizedFilePath = fc.cleanLinuxPath(os.path.join(downSampledEMFolder, imageFolderName, resizedImageName))
			
			im = Opener().openImage(filePath)
			IJ.log('Am I going to process the image: im.height = ' + str(im.height) + ' - tileHeight = ' + str(tileHeight) + ' tile number ' + str(k))
			if im.height == tileHeight: # crop a few lines at the top only if it has not already been done (sometimes the pipeline gets rerun)
				im = fc.crop(im,cropRoi)
				im = fc.normLocalContrast(im, normLocalContrastSize, normLocalContrastSize, 3, True, True)
				# IJ.run(im, 'Replace value', 'pattern=0 replacement=1') # only for final waferOverview
				FileSaver(im).saveAsTiff(filePath)
				
			if not os.path.isfile(resizedFilePath):
				im = fc.resize(im, scaleFactor)
				FileSaver(im).saveAsTiff(resizedFilePath)
				IJ.log('Image resized to ' + resizedFilePath)
			im.close()
Exemple #2
0
def contrastImage():
	while atomicI.get() < nPaths:
		k = atomicI.getAndIncrement()
		if k < nPaths:
			im = IJ.openImage(toContrastPaths[k][0])
			im = fc.normLocalContrast(im, normLocalContrastSize, normLocalContrastSize, 3, True, True)
			IJ.save(im, toContrastPaths[k][1])
			im.close()
Exemple #3
0
    im = IJ.openImage(imPath)
    im = fc.minMax(im, meanMin, meanMax)
    IJ.run(im, '8-bit', '')
    IJ.run(im, 'Flip Horizontally',
           '')  # {Leica DMI, NikonTiEclipse} to Merlin
    IJ.save(im, imPath)
    IJ.log('Image ' + imPath + ' thresholded 8-bited')

# process all other channels that are not refChannel: normLocalContrast, threshold, 8-bit
for (dirpath, dirnames, filenames) in os.walk(LMDataFolder):
    for filename in filenames:
        if (os.path.splitext(filename)[1]
                == '.tif') and not (refChannel in filename):
            imPath = os.path.join(dirpath, filename)
            im = IJ.openImage(imPath)
            im = fc.normLocalContrast(im, normLocalContrastSizeFluo,
                                      normLocalContrastSizeFluo, 3, True, True)
            im = fc.minMax(im, minMaxFluo[0], minMaxFluo[1])
            IJ.run(im, '8-bit', '')
            if flipHorizontally:
                IJ.run(im, 'Flip Horizontally', '')  # Leica DMI to Merlin
            IJ.save(im, imPath)
            IJ.log('Image ' + imPath + ' processed')

# add a contrasted reference channel (e.g., contrast the brightfield channel)
IJ.log('Adding a contrasted channel')
contrastedChannel = 'contrasted' + refChannel
channels.append(contrastedChannel)
toContrastPaths = []

for (dirpath, dirnames, filenames) in os.walk(LMDataFolder):
    for filename in filenames:
                    LMFolder, 'exported_downscaled_1_' + channel,
                    'exported_downscaled_1_' + channel + '_' +
                    str(l).zfill(4) + '.tif'))

            patch = Patch.createPatch(pZ, LMMosaicsPath)
            layerZ.add(patch)
            IJ.log('Setting the affineTransform ' + str(affTransform))
            patch.setAffineTransform(affTransform)
            patch.updateBucket()

            bb = Rectangle(0, 0, widthEM, heightEM)
            affineCroppedIm = loaderZ.getFlatImage(layerZ, bb, 1, 0x7fffffff,
                                                   ImagePlus.GRAY8, Patch,
                                                   layerZ.getAll(Patch), True,
                                                   Color.black, None)
            affineCroppedIm = fc.normLocalContrast(affineCroppedIm, 50, 50, 3,
                                                   True, True)
            IJ.run(affineCroppedIm, 'Median...', 'radius=2')
            affineCroppedImPath = os.path.join(
                affineCroppedFolder,
                'affineCropped_' + channel + '_' + str(l).zfill(4) + '.tif')
            IJ.save(affineCroppedIm, affineCroppedImPath)
            affineCroppedIm.close()

            layerZ.remove(patch)
            layerZ.recreateBuckets()
            IJ.log('Has been written: ' + str(affineCroppedImPath))
fc.closeProject(pZ)  # close dummy trakem

# # # # # # create the median folders
# # # # # for channel in channels[:-2]: # the fluorescent channels, excluding the brightfield and contrastedBrightfield channels
# # # # # affineCroppedFolder = os.path.join(LMFolder, 'affineCropped_' + channel)