예제 #1
0
 def create_preview(self, file):
     image = imaging.load(file)[0]
     image = imaging.filters.norm(image, 0.01, 0.01, 0, 255)
     # image = imaging.filters.zoom(image, 0.25)
     preview_file = '{}.preview.png'.format(file)
     imaging.save(image, preview_file)
     return preview_file
예제 #2
0
def topng(mrc, scale, force):
    png = pyfs.rext(mrc, 'png')
    png = mrc + '.png'
    if not force and pyfs.exists(png):
        return
    print(mrc, '->', png)
    image = imaging.load(mrc)[0]
    image = imaging.filters.zoom(image, scale)
    imaging.save(image, png)
예제 #3
0
 def create_preview(self, file):
     try:
         image = imaging.load(file)[0]
         image = imaging.filters.norm(image, 0.01, 0.01, 0, 255)
         image = imaging.filters.zoom(image, 0.25)
         preview_file = '{}.preview.png'.format(file)
         imaging.save(image, preview_file)
         return preview_file
     except Exception as e:
         print(e)
         return None
예제 #4
0
def test():
    path   = "cache/13apr24b_00002sq_v02_00004hl_v01_00002en.mrc"
    start  = 2
    stop   = 80
    levels = 10
    ring   = 1.2
    factor = 0.25
    psize  = 2
    emax   = 4.0
    vmin   = 0.01
    image = filters.zoom(load(path), factor)
    pyramid = mkpyramid(image, start, stop, levels, ring)
    features = find_peaks(pyramid, vmin, emax, psize)
    save_pyramid(pyramid, "out")
    save(keypoints.draw(image, features[-3000:]), "out.png")
예제 #5
0
    def process_data(self, acquisition_data, motion_correction_data):
        if motion_correction_data.dose_weighted_image_file is not None:
            aligned_image_file = motion_correction_data.dose_weighted_image_file
        else:
            aligned_image_file = motion_correction_data.aligned_image_file
        output_file_base = os.path.join(self.session.processing_directory, acquisition_data.base_name)
        output_file = '{}_dogpicker.json'.format(output_file_base)


        try:
            image = imaging.load(aligned_image_file)[0]    
       
            mint = None
            maxt = None
            debug = None
            meanmax = None
            sizemin = int(np.min(motion_correction_data.dimensions)/50)
            sizes = np.logspace(np.log10(sizemin), np.log10(sizemin*10) ,num=20)
            idogpicker_data = {}
            for size in sizes:
                keys = list(self.detect(image, size, mint, maxt, debug, meanmax))
            
                LOG.debug("%i -> %i" % (size, len(keys)))
                idogpicker_data[int(size+0.5)] = keys
            with open(output_file,'w') as fp:
                json.dump(pretty_floats(idogpicker_data),fp)
            data_model = DogpickerData(acquisition_data.base_name)
            data_model.time = time.time()
            data_model.dogpicker_file = output_file
        

       
            data_model.push(self.session.db)
        
        except Exception as e:
            LOG.error("Dogpicker failed")
            LOG.error(e)
            self.failed.append(acquisition_data.base_name)
            ResourceManager.release_cpus(self.required_cpus)
            return

        

        self.finished.append(acquisition_data.base_name)

        ResourceManager.release_cpus(self.required_cpus)
예제 #6
0
def binby(items, binner):
    bins = {}
    for item in items:
        bin = binner(item)
        if bin not in bins:
            bins[bin] = []
        bins[bin] += [item]
    return bins


def save(pyramid, keys, root):
    sizes, octave = pyramid[0]
    octave = filters.norm(octave, 5, 5, 0, 255)
    key_levels = binby(keys, lambda x: int(x.octave))
    for l, level in enumerate(octave):
        drawn = level
        if l in key_levels:
            drawn = keypoints.draw(level, key_levels[l])
        save(drawn, pyfs.join(root, "%f.png" % sizes[l]), norm=False)


if __name__ == "__main__":
    import sys
    import imaging
    a = imaging.load(
        "/Users/craigyk/Desktop/classifier/cache/13apr24b_00002sq_v02_00002hl_v01_00003en.mrc"
    )
    a = imaging.filters.zoom(a, 0.25)
    features = detect(a, start=1.5, levels=5)
    save(draw(a, features), sys.argv[1])
예제 #7
0
 def get_dose_from_mrc(self, mrc_path):
     imfile = imaging.load(mrc_path)
     return (imfile.mean(), imfile.shape[-2::-1])
예제 #8
0
 def preview_montage(self, src, dst, section=0):
     image_stack = imaging.load(str(src), format='mrc')
     image = image_stack[section]
     image = imaging.filters.norm(image, 0.01, 0.01, 0, 255)
     imaging.save(image, str(dst), norm=False)
     return dst