Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p.plane_count = SizeZ * SizeT * SizeC
p = writeOMETIFFplanes(p, SizeT=SizeT, SizeZ=SizeZ, SizeC=SizeC, order=dimorder)
for c in range(SizeC):
if pixeltype == 'unit8':
p.Channel(c).SamplesPerPixel = 1
if pixeltype == 'unit16':
p.Channel(c).SamplesPerPixel = 2
omexml.structured_annotations.add_original_metadata(bioformats.omexml.OM_SAMPLES_PER_PIXEL, str(SizeC))
# Converting to omexml
xml = omexml.to_xml()
# write file and save OME-XML as description
tifffile.imwrite(filepath, img6d, metadata={'axes': dimorder}, description=xml)
return filepath
def output_image(self, img, filename, tif=False):
"""Output calculated image to file.
Parameters
----------
img:array
Image.
filename:str
Output file name.
tif:bool
Store in TIF format?
"""
if tif:
from tifffile import imwrite
imwrite(filename, np.array(img), photometric='rgb')
else:
img.save(filename)
def output_image(self, img, filename, tif=False):
"""Output calculated image to file.
Parameters
----------
img:array
Image.
filename:str
Output file name.
tif:bool
Store in TIF format?
"""
if tif:
from tifffile import imwrite
imwrite(filename, np.array(img), photometric='rgb')
else:
img.save(filename)
p.plane_count = SizeZ * SizeT * SizeC
p = writeOMETIFFplanes(p, SizeT=SizeT, SizeZ=SizeZ, SizeC=SizeC, order=dimorder)
for c in range(SizeC):
if pixeltype == 'unit8':
p.Channel(c).SamplesPerPixel = 1
if pixeltype == 'unit16':
p.Channel(c).SamplesPerPixel = 2
omexml.structured_annotations.add_original_metadata(bioformats.omexml.OM_SAMPLES_PER_PIXEL, str(SizeC))
# Converting to omexml
xml = omexml.to_xml()
# write file and save OME-XML as description
tifffile.imwrite(filepath, img6d, metadata={'axes': dimorder}, description=xml)
return filepath
p.plane_count = SizeZ * SizeT * SizeC
p = writeOMETIFFplanes(p, SizeT=SizeT, SizeZ=SizeZ, SizeC=SizeC, order=dimorder)
for c in range(SizeC):
if pixeltype == 'unit8':
p.Channel(c).SamplesPerPixel = 1
if pixeltype == 'unit16':
p.Channel(c).SamplesPerPixel = 2
omexml.structured_annotations.add_original_metadata(bioformats.omexml.OM_SAMPLES_PER_PIXEL, str(SizeC))
# Converting to omexml
xml = omexml.to_xml()
# write file and save OME-XML as description
tifffile.imwrite(filepath, img6d, metadata={'axes': dimorder}, description=xml)
return filepath
for i in range (image.shape[0]):
im=image[i,...]
# processing image
means[i,...], mseEst[i,...] = prediction.tiledPredict(im, net ,ps=args.tileSize, overlap=args.tileOvp,
device=device,
noiseModel=noiseModel)
if im.shape[0]==1:
means=means[0]
mseEst=mseEst[0]
outpath=args.output
filename=os.path.basename(f).replace('.tif','_MMSE-PN2V.tif')
outpath=os.path.join(outpath,filename)
print('writing',outpath, mseEst.shape)
imwrite(outpath, mseEst.astype(np.float32), imagej=True)
outpath=args.output
filename=os.path.basename(f).replace('.tif','_Prior-PN2V.tif')
outpath=os.path.join(outpath,filename)
print('writing',outpath, means.shape)
imwrite(outpath, means.astype(np.float32), imagej=True)
def write_tiff_createfolder(path: Union[str, pathlib.Path], nparray: np.ndarray, **opt_kwargs):
"""
given a
path: to a tiff file of type pathlib.Path (or str), and
nparray: numpy array holding an image/volume
creates all necessary folders in the path (in case they don't exist already)
and writes the numpy array as a tiff
"""
if not isinstance(path, pathlib.Path):
path = pathlib.Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
tifffile.imwrite(str(path), nparray, **opt_kwargs)
#imsave(str(path), nparray, **opt_kwargs) #