Example #1
0
	def displayImage(self, imp, show = True):
		imp.setDisplayMode(IJ.COMPOSITE)
		enhancer = ContrastEnhancer()
		enhancer.setUseStackHistogram(True)
		splitter = ChannelSplitter()
		for c in range(1, imp.getNChannels() + 1):
			imp.c = c
			enhancer.stretchHistogram(imp, 0.35)
		if show:
			imp.show()
Example #2
0
def getPreview(image):
	enhancer = ContrastEnhancer()
	projector = ZProjector()
	splitter = ChannelSplitter()
	imp1 = ImagePlus("CH1", )
	width, height, channels, slices, frames = image.getDimensions()
	chimps = []
	for ch in range(1, channels + 1):
		projector = ZProjector(ImagePlus("C%i" % ch, splitter.getChannel(image, ch)))
		projector.setMethod(ZProjector.MAX_METHOD)
		projector.doProjection()
		proj = projector.getProjection()
		enhancer.equalize(proj)
		chimps.append(proj)
		
	return RGBStackMerge.mergeChannels(chimps, False)
Example #3
0
    def cubify_ROI(self, e):
        self.manualROI_name = self.name + "_manualROI-" + self.textfield3.text

        # warn the user if that ROI exists already in the processed data
        self.processed_files = listdir(self.output_path)
        self.out_core_names = get_core_names(self.processed_files, self.file_core_name)
        if self.manualROI_name in self.out_core_names:
            print("##################                       ##################")
            print("CAREFUL!!!! This ROI already exists in your processed data:")
            print("##################                       ##################")

        print(self.manualROI_name)

        # set square roi size in the low resolution level
        gui_adjust = 128  # for historic reasons
        hr_L = int(self.textfield1.text) * gui_adjust
        # convert back to low resolution
        self.L = hr_L / self.binFactor
        # get info
        tit = self.lr_dapi.getTitle()
        self.roi = self.lr_dapi.getRoi()

        # get corners
        corners = get_corners(self.roi, self.L)
        self.corners_cleaned = clean_corners(corners, self.roi, self.L)
        # get the overlay
        self.ov = overlay_corners(self.corners_cleaned, self.L)
        self.ov = overlay_roi(self.roi, self.ov)
        # write roi name
        self.ov = write_roi_numbers(self.ov, self.corners_cleaned, self.L)
        # overlay
        self.lr_dapi.setOverlay(self.ov)
        self.lr_dapi.updateAndDraw()

        # open the Xth highest resolution one to see if it is in focus
        if int(self.textfield5.text) != 0:
            pir_for_focus = int(self.textfield5.text)
            bf_corr = self.binFactor / (self.binStep ** (pir_for_focus - 1))
            min_x = int(min([x[0] for x in self.corners_cleaned]) * bf_corr)
            min_y = int(min([x[1] for x in self.corners_cleaned]) * bf_corr)
            max_x = int((max([x[0] for x in self.corners_cleaned]) + self.L) * bf_corr)
            max_y = int((max([x[1] for x in self.corners_cleaned]) + self.L) * bf_corr)
            series_num = self.high_res_index + pir_for_focus - 1
            self.med_res_image = open_czi_series(
                self.input_path, series_num,
                rect=[min_x, min_y, max_x - min_x, max_y - min_y])  # read the image
            # play with that one, and do the real processing in the background
            self.med_res_image.show()
            self.med_res_image.setDisplayMode(IJ.COMPOSITE)
            color_order = ['Grays', 'Green', 'Red', 'Cyan']
            for c in range(self.med_res_image.getNChannels()):
                self.med_res_image.setC(c + 1)
                IJ.run(color_order[c])
                ContrastEnhancer().stretchHistogram(self.med_res_image, 0.35)
                self.med_res_image.updateAndDraw()
            # rename
            self.med_res_image.setTitle(self.manualROI_name)
Example #4
0
    def save_registration_image(self):
        reg_text_info = self.textfield4.text.split(',')
        reg_pir_num = int(reg_text_info[0])
        reg_channel = int(reg_text_info[1])
        self.reg_final_res = float(reg_text_info[2])

        self.forreg_output_path = path.join(self.output_path, "000_Slices_for_ARA_registration")

        if path.isdir(self.forreg_output_path):
            print("Output path for low resolution slices was already created")
        else:
            mkdir(self.forreg_output_path)
            print("Output path for low resolution slices created")

        # check that this slice has not been saved before
        reg_slice_name = path.join(self.forreg_output_path, self.name)
        if path.isfile(reg_slice_name + '.tif'):
            print("Registration slice already exists")
        else:
            # save otherwise
            print("Saving for registration channel {} at {} um/px".format(reg_channel, self.reg_final_res))
            # get the Xth resolution image and Xth channel for saving it for registration
            series_num = self.high_res_index + reg_pir_num
            self.raw_reg_image = open_czi_series(self.input_path, series_num)  # read the image
            self.regist_image = extractChannel(self.raw_reg_image, reg_channel, 1)
            ContrastEnhancer().stretchHistogram(self.regist_image, 0.35)
            # self.regist_image.show()

            self.regist_image.getProcessor().resetRoi()
            # reset min and max automatically
            # convert to 8-bit (which also applies the contrast)
            # ImageConverter(self.regist_image).convertToGray8()
            # convert to Xum/px so that it can be aligned to ARA
            reg_im_bin_factor = self.binStep ** reg_pir_num
            regres_resolution = reg_im_bin_factor * self.res_xy_size
            rescale_factor = regres_resolution / self.reg_final_res
            new_width = int(rescale_factor * self.regist_image.getWidth())
            # self.lr_dapi_reg.getProcessor().scale(rescale_factor, rescale_factor)
            ip = self.regist_image.getProcessor().resize(new_width)
            self.regist_image.setProcessor(ip)
            # Add the information to the metadata
            self.regist_image.getCalibration().pixelWidth = self.reg_final_res
            self.regist_image.getCalibration().pixelHeight = self.reg_final_res
            self.regist_image.getCalibration().pixelDepth = 1
            self.regist_image.getCalibration().setXUnit("micrometer")
            self.regist_image.getCalibration().setYUnit("micrometer")
            self.regist_image.getCalibration().setZUnit("micrometer")
            # self.lr_dapi_reg.getProcessor().resetRoi()
            IJ.saveAsTiff(self.regist_image, reg_slice_name)
            self.regist_image.close()
            self.regist_image.flush()
            print("Slice for registration saved")
Example #5
0
    def open_lowres_image(self, e):
        sender = e.getSource()
        IJ.run("Close All")
        if not e.getValueIsAdjusting():
            self.name = sender.getSelectedValue()
            print(self.name)
            # parse the slice number
            self.sl_num = int(self.name.split('-')[-1])
            print("Opening slice " + str(self.sl_num))

            if not path.exists(self.input_path):
                print("I don't find the file, which is weird as I just found it before")
            else:
                # get the number of piramids for that image, the index of highres and the binning
                self.num_of_piramids = self.num_of_piramids_list[self.sl_num]
                self.high_res_index = self.max_res_indexes[self.sl_num]
                self.binFactor = self.binFactor_list[self.sl_num]
                self.binStep = self.binStep_list[self.sl_num]
                # get the lowest resolution binned, depending on the number
                # of resolutions. The order is higher to lower.
                series_num = self.high_res_index + self.num_of_piramids - 1
                self.low_res_image = open_czi_series(self.input_path, series_num)  # read the image
                # save the resolution (every image has the high-resolution information)
                self.res_xy_size = self.low_res_image.getCalibration().pixelWidth
                self.res_units = self.low_res_image.getCalibration().getXUnit()
                # play with that one, and do the real processing in the background
                # select the DAPI channel and adjust the intensity
                self.lr_dapi = extractChannel(self.low_res_image, 1, 1)
                ContrastEnhancer().stretchHistogram(self.lr_dapi, 0.35)
                self.lr_dapi.setTitle(self.name)
                self.lr_dapi.show()
                # reposition image
                self.lr_dapi.getWindow().setLocation(420, 10)
                self.lr_dapi.updateAndDraw()

                # clean
                self.low_res_image.close()
                self.low_res_image.flush()
 num_of_piramids = num_of_piramids_list[sl_num]
 binFactor = binFactor_list[sl_num]
 high_res_index = max_res_indexes[sl_num]
 binStep = binStep_list[sl_num]
 # open the image
 # get the Xth resolution binned, depending on the number
 # of resolutions. The order is higher to lower.
 series_num = high_res_index + piramid_to_open
 raw_image = open_czi_series(input_path, series_num)
 # save the resolution (every image has the high-resolution information)
 res_xy_size = raw_image.getCalibration().pixelWidth
 res_units = raw_image.getCalibration().getXUnit()
 # select the requested channel and adjust the intensity
 regist_image = extractChannel(raw_image, channel_to_save, 1)
 # TODO: test if contrast enhancement and background sustraction are needed for registration
 ContrastEnhancer().stretchHistogram(regist_image, 0.35)
 # IMPLEMENT BACKGROUND SUSTRACTION HERE
 regist_image.setTitle(sl_name)
 #ch_image.show()
 # clean
 raw_image.close()
 raw_image.flush()
 # convert to Xum/px so that it can be aligned to ARA
 reg_im_bin_factor = binStep**piramid_to_open
 regres_resolution = reg_im_bin_factor * res_xy_size
 rescale_factor = regres_resolution / final_resolution
 new_width = int(rescale_factor * regist_image.getWidth())
 # self.lr_dapi_reg.getProcessor().scale(rescale_factor, rescale_factor)
 ip = regist_image.getProcessor().resize(new_width)
 regist_image.setProcessor(ip)
 # Add the information to the metadata
Example #7
0
import glob

arguments = docopt(__doc__, version='NER 0.1')

input_dir = arguments['INPUT']
output_dir = arguments['OUTPUT']
filter_window = float(arguments['--filter-window']) if arguments['--filter-window'] else 5.0
gamma = float(arguments['--gamma']) if arguments['--gamma'] else 0.50
channel = int(arguments['--channel']) if arguments['--channel'] else 1
objective = int(arguments['--objective']) if arguments['--objective'] else 20
microscope = arguments['--microscope'] if arguments['--microscope'] else "SD"
pixel_size = float(arguments['--pixel-size']) if arguments['--pixel-size'] else None
rolling_ball_size = int(arguments['--rolling-ball-size']) if arguments['--pixel-size'] else 30

channel_splitter = ChannelSplitter()
contrast_enhancer = ContrastEnhancer()
contrast_enhancer.setNormalize(True)

if pixel_size is None:
  if objective == 20 and microscope == "SD":
    pixel_size = 0.5089
  else:
    pixel_size = 1.0

files = glob.glob(input_dir + "*.tif")
files.sort()

frame_i = 1
for file in files:
  print("Processing frame \033[1m" + str(frame_i) + "\033[0m")
  frame = IJ.openImage(file) # ImagePlus