How to use the aicsimageio.omeTifWriter.OmeTifWriter function in aicsimageio

To help you get started, we’ve selected a few aicsimageio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AllenInstitute / aics-ml-segmentation / aicsmlsegment / bin / exp_scheduler.py View on Github external
# Assume:  TCZYX
                img = img0[tt, args.InputCh,:,:,:].astype(float)
                img = input_normalization(img, args)

                if len(args.ResizeRatio)>0:
                    img = resize(img, (1, args.ResizeRatio[0], args.ResizeRatio[1], args.ResizeRatio[2]), method='cubic')
                    for ch_idx in range(img.shape[0]):
                        struct_img = img[ch_idx,:,:,:] # note that struct_img is only a view of img, so changes made on struct_img also affects img
                        struct_img = (struct_img - struct_img.min())/(struct_img.max() - struct_img.min())
                        img[ch_idx,:,:,:] = struct_img

                # apply the model
                output_img = model_inference(model, img, softmax, args)

                for ch_idx in range(len(args.OutputCh)//2):
                    writer = omeTifWriter.OmeTifWriter(args.OutputDir + pathlib.PurePosixPath(fn).stem + '_T_'+ f'{tt:03}' +'_seg_'+ str(args.OutputCh[2*ch_idx])+'.ome.tif')
                    if args.Threshold<0:
                        out = output_img[ch_idx].astype(float)
                        out = resize(out, (1.0, 1/args.ResizeRatio[0], 1/args.ResizeRatio[1], 1/args.ResizeRatio[2]), method='cubic')
                        writer.save(out)
                    else:
                        out = output_img[ch_idx] > args.Threshold
                        out = resize(out, (1.0, 1/args.ResizeRatio[0], 1/args.ResizeRatio[1], 1/args.ResizeRatio[2]), method='nearest')
                        out = out.astype(np.uint8)
                        out[out>0]=255
                        writer.save(out)
        else:
            img = img0[0,:,:,:].astype(float)
            if img.shape[1] < img.shape[0]:
                img = np.transpose(img,(1,0,2,3))
            img = img[args.InputCh,:,:,:]
            img = input_normalization(img, args)
github AllenInstitute / aics-ml-segmentation / aicsmlsegment / bin / curator / curator_merging.py View on Github external
writer = omeTifWriter.OmeTifWriter(mask_fn)
                writer.save(crop_mask)
                df['merging_mask'].iloc[index]=mask_fn

                need_mask = input('Do you need to add an excluding mask for this image, enter y or n:  ')
                if need_mask == 'y':
                    create_merge_mask(raw_img, seg1.astype(np.uint8), seg2.astype(np.uint8), 'excluding mask')

                    mask_fn = args.ex_mask_path + os.sep + os.path.basename(row['raw'])[:-5] + '_mask.tiff'
                    crop_mask = np.zeros(seg1.shape, dtype=np.uint8)
                    for zz in range(crop_mask.shape[0]):
                        crop_mask[zz,:,:] = draw_mask[:crop_mask.shape[1],:crop_mask.shape[2]]

                    crop_mask = crop_mask.astype(np.uint8)
                    crop_mask[crop_mask>0]=255
                    writer = omeTifWriter.OmeTifWriter(mask_fn)
                    writer.save(crop_mask)
                    df['excluding_mask'].iloc[index]=mask_fn


            df.to_csv(args.csv_name, index=False)
            

        #########################################
        # generate training data:
        #  (we want to do this step after "sorting"
        #  (is mainly because we want to get the sorting 
        #  step as smooth as possible, even though
        #  this may waster i/o time on reloading images)
        # #######################################
        print('finish merging, start building the training data ...')
        existing_files = glob(args.train_path+os.sep+'img_*.ome.tif')
github AllenInstitute / aics-ml-segmentation / aicsmlsegment / bin / curator / curator_merging.py View on Github external
reader = AICSImage(row['excluding_mask'])
                    img = reader.data
                    assert img.shape[0]==1 and img.shape[1]==1
                    ex_mask = img[0,0,:,:,:]>0
                    cmap[ex_mask>0]=0
 
                
                writer = omeTifWriter.OmeTifWriter(args.train_path + os.sep + 'img_' + f'{training_data_count:03}' + '.ome.tif')
                writer.save(struct_img)

                seg1 = seg1.astype(np.uint8)
                seg1[seg1>0]=1
                writer = omeTifWriter.OmeTifWriter(args.train_path + os.sep + 'img_' + f'{training_data_count:03}' + '_GT.ome.tif')
                writer.save(seg1)

                writer = omeTifWriter.OmeTifWriter(args.train_path + os.sep + 'img_' + f'{training_data_count:03}' + '_CM.ome.tif')
                writer.save(cmap)
        print('training data is ready')