How to use aicsimageprocessing - 6 common examples

To help you get started, we’ve selected a few aicsimageprocessing 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
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)

            if len(args.ResizeRatio)>0:
                img = resize(img, (1, args.ResizeRatio[0], args.ResizeRatio[1], args.ResizeRatio[2]), method='cubic')
github AllenInstitute / aics-ml-segmentation / aicsmlsegment / bin / exp_scheduler.py View on Github external
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)

            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 +'_seg_'+ str(args.OutputCh[2*ch_idx])+'.ome.tif')
                if args.Threshold<0:
                    writer.save(output_img[ch_idx].astype(float))
                else:
                    out = output_img[ch_idx] > args.Threshold
                    out = out.astype(np.uint8)
                    out[out>0]=255
github AllenInstitute / aics-ml-segmentation / aicsmlsegment / utils.py View on Github external
img = img.astype(float)
        if img.shape[1] < img.shape[0]:
                img = np.transpose(img,(1,0,2,3))
        img = img[args.InputCh,:,:,:] #  fancy indexing atually creates a copy, not a view

    # normalization
    if args.mode == 'train':
        for ch_idx in range(args.nchannel):
            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())
    elif not args.Normalization == 0:
        img = input_normalization(img, args)
    
    # rescale
    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

    return img
github AllenInstitute / aics-ml-segmentation / aicsmlsegment / bin / exp_scheduler.py View on Github external
elif args.mode == 'eval_file':

        fn = args.InputFile
        print(fn)
        data_reader = AICSImage(fn)
        img0 = data_reader.data
        if args.timelapse:
            assert data_reader.shape[0]>1

            for tt in range(data_reader.shape[0]):
                # 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
github AllenInstitute / aics-ml-segmentation / aicsmlsegment / bin / dl_inference.py View on Github external
# 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
            # import pdb; pdb.set_trace()
            output_img = apply_on_image(model, img, model.final_activation, args_inference)

            # extract the result and write the output
            if len(config['OutputCh'])==2:
                if config['Threshold']<0:
                    out = output_img[0]
                    out = (out - out.min()) / (out.max()-out.min())
                    if len(config['ResizeRatio'])>0:
                        out = resize(out, (1.0, 1/config['ResizeRatio'][0], 1/config['ResizeRatio'][1], 1/config['ResizeRatio'][2]), method='cubic')
                    out = out.astype(np.float32)
                    out = (out - out.min()) / (out.max()-out.min())
                else:
                    out = remove_small_objects(output_img[0] > config['Threshold'], min_size=2, connectivity=1) 
                    out = out.astype(np.uint8)
                    out[out>0]=255
                imsave(config['OutputDir'] + os.sep + pathlib.PurePosixPath(fn).stem + '_struct_segmentation.tiff', out)
            else:
                for ch_idx in range(len(config['OutputCh'])//2):
                    if config['Threshold']<0:
                        out = output_img[ch_idx]
                        out = (out - out.min()) / (out.max()-out.min())
                        out = out.astype(np.float32)
                    else:
                        out = output_img[ch_idx] > config['Threshold']
                        out = out.astype(np.uint8)
github AllenInstitute / aics-ml-segmentation / aicsmlsegment / bin / exp_scheduler.py View on Github external
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)

            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

aicsimageprocessing

A generalized scientific image processing module from the Allen Institute for Cell Science.

Allen Institute Software Lice…
Latest version published 1 year ago

Package Health Score

42 / 100
Full package analysis

Popular aicsimageprocessing functions

Similar packages