示例#1
0
    def __init__(self,
                 axis,
                 one_axis,
                 two_axis,
                 corr_axis,
                 imgSrc,
                 rootPath,
                 figure=None,
                 load_callback=None):
        """initialization function which will plot the imagematrix passed in and set the bounds according the bounds specified by extent
        
        keywords)
        axis)the matplotlib axis to plot the image into
        one_axis) the matplotlib axis to plot the cutout of the fixed point when using the corresponding point functionality
        two_axis) the matplotlib axis to plot the cutout of the point that should be moved when using the corresponding point functionality
        corr_axis) the matplotlib axis to plot out the matrix of correlation values found when using the corresponding point functionality
        imagefile) a string with the path of the file which contains the full resolution image that should be used when calculating the corresponding point funcationality
         currently the reading of the image is using PIL so the path specified must be an image which is PIL readable
        imagematrix) a numpy 2d matrix containing a low resolution varsion of the full resolution image, for the purposes of faster plotting/memory management
        extent) a list [minx,maxx,miny,maxy] of the corners of the image.  This will specify the scale of the image, and allow the corresponding point functionality
        to specify how much the movable point should be shifted in the units given by this extent.  If omitted the units will be in pixels and extent will default to
        [0,width,height,0].
       
        """
        #define the attributes of this class
        self.axis = axis
        self.one_axis = one_axis
        self.two_axis = two_axis
        self.corr_axis = corr_axis

        #initialize the images for the various subplots as None
        self.oneImage = None
        self.twoImage = None
        self.corrImage = None
        self.imgSrc = imgSrc
        self.imgCollection = ImageCollection(rootpath=rootPath,
                                             imageSource=imgSrc,
                                             axis=self.axis)

        (x, y) = imgSrc.get_xy()
        bbox = imgSrc.calc_bbox(x, y)
        self.imgCollection.set_view_home()
        self.imgCollection.load_image_collection(load_callback=load_callback)

        self.maxvalue = 512
        self.currentPosLine2D = Line2D([x], [y],
                                       marker='o',
                                       markersize=7,
                                       markeredgewidth=1.5,
                                       markeredgecolor='r',
                                       zorder=100)
        self.axis.add_line(self.currentPosLine2D)
        self.axis.set_title('Mosaic Image')
        self.fig = figure
        self.update_pos_cursor()
示例#2
0
    def run(self):
        full_executor = ThreadPoolExecutor(max_workers=self.max_workers)

        # Split available worker threads between training data preparation and post
        # processing (if possible).
        if self.max_workers > 1:
            workers = min(self.max_workers - 1,
                          round(self.max_workers * self.train_workers_ratio))
            train_executor = ThreadPoolExecutor(max_workers=workers)
            post_executor = ThreadPoolExecutor(max_workers=self.max_workers -
                                               workers)
        else:
            train_executor = full_executor
            post_executor = full_executor

        images = ImageCollection(self.images, executor=full_executor)
        images.prune_corrupt_images()
        total_images = len(images)

        if total_images == 0:
            print('No image files to process.')
            return
        elif total_images < self.clusters:
            print(
                '{} clusters were requested but only {} images are there. Reducing clusters to {}.'
                .format(self.clusters, total_images, total_images))
            self.clusters = total_images

        if self.clusters > 1:
            clusters = images.make_clusters(number=self.clusters)
        else:
            clusters = [images]

        detector = AutoencoderSaliencyDetector(self.patch_size,
                                               stride=self.detector_stride,
                                               hidden=self.latent_size)

        jobs = []

        for i, cluster in enumerate(clusters):
            cluster.set_executor(train_executor)
            print("Cluster {} of {}".format(i + 1, self.clusters))
            threshold = self.process_cluster(detector, cluster)
            jobs.extend([
                post_executor.submit(self.postprocess_map, image, threshold)
                for image in cluster
            ])

        wait(jobs)
示例#3
0
#tetra_fn='/home/carlos/PycharmProjects/margreet_code_review/rough_ave.tif'
#image_fn ='/home/carlos/PycharmProjects/margreet_code_review/hel4.pma'

tmp=Mapping(tetra_fn)

if 1:
    root=os.path.normpath("N:/tnw/BN/CMJ/Shared/Margreet/20181203_HJ_training/#3.10_0.1mg-ml_streptavidin_50pM_HJC_G_movies")
    name='hel4.pma'

else:
    root=os.path.normpath("N:/tnw/BN/CMJ/Shared/Margreet/181218 - First single-molecule sample (GattaQuant)/RawData") 
    name='Spooled files.sifx'
 
image_fn=os.path.join(root,name)
imc = ImageCollection(tetra_fn, image_fn) 
# better: give image directory, and search for specific name or extension
img = imc.get_image(1)

#tmp._tf2_matrix
#imc.mapping._tf2_matrix
#imc.pts_number # is too 19 for the pma
#import matplotlib.pyplot as plt; plt.imshow(imc.im_mean20_correct)

traces_fn=os.path.join(root,name[:-4]+'-P.traces') 
Ncolours=2
if os.path.isfile(traces_fn):
     with open(traces_fn, 'r') as infile:
         Nframes = np.fromfile(infile, dtype = np.int32, count = 1).item()
         Ntraces = np.fromfile(infile, dtype = np.int16, count = 1).item()
         rawData = np.fromfile(infile, dtype = np.int16, count = Ncolours*Nframes * Ntraces)