-
Notifications
You must be signed in to change notification settings - Fork 52
Description
edit: Problem solved by removing the second arrayjoin im = pyvips.Image.arrayjoin(im.bandsplit(), across=1)
Hi,
I was using the convert.py code written by @jcupitt, and it works if the image is on the disk, but if I included the code after an arrayjoin it saves a max file of 2.56GB, and it stops. The file should be around 3.47GB.
I am trying to figure out if I am hitting the 2048 file limit on Windows. I am stitching more than 3000 images.
Here is the code I am using:
#load a local image already stitched using arrayjoin method
im = pyvips.Image.new_from_file(sys.argv[1])
if im.hasalpha():
im = im[:-1]
image_height = im.height
image_bands = im.bands
# split to separate image planes and stack vertically ready for OME
im = pyvips.Image.arrayjoin(im.bandsplit(), across=1)
# set minimal OME metadata
# before we can modify an image (set metadata in this case), we must take a
# private copy
im = im.copy()
im.set_type(pyvips.GValue.gint_type, "page-height", image_height)
im.set_type(pyvips.GValue.gstr_type, "image-description",
f"""<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
<Image ID="Image:0">
<!-- Minimum required fields about image dimensions -->
<Pixels DimensionOrder="XYCZT"
ID="Pixels:0"
SizeC="{image_bands}"
SizeT="1"
SizeX="{im.width}"
SizeY="{image_height}"
SizeZ="1"
Type="uint8">
</Pixels>
</Image>
</OME>""")
im.tiffsave(sys.argv[2], compression="jpeg", tile=True,
tile_width=512, tile_height=512,
pyramid=True, subifd=True)
That code only works as I mentioned if I use it to first load an image saved on the drive i.e. result.v and successfully convert it to tiff file that I can inspect with QuPath.
But this code doesn't save the file completely, it looks like there is some limitation.
tiles_across = 49
tiles = []
# Sort files based on the [y,x] values
def sort_by_yx(filename):
match = re.search(r'\[(\d+),(\d+)\].*\.png', filename)
if match:
y_value = int(match.group(1))
x_value = int(match.group(2))
return y_value, x_value
else:
return float('inf'), float('inf')
directory = sys.argv[1]
files = os.listdir(directory)
sorted_files = sorted(files, key=sort_by_yx)
tile_size = None # Variable to store the tile size
tiles = []
for filename in sorted_files:
if os.path.isfile(os.path.join(directory, filename)):
tile = pyvips.Image.new_from_file(os.path.join(directory, filename), access="sequential")
tile = tile.crop(overlap, overlap, tile.width - overlap, tile.height - overlap)
tiles.append(tile)
im = pyvips.Image.arrayjoin(tiles, across=(tiles_across))
if im.hasalpha():
im = im[:-1]
image_height = im.height
image_bands = im.bands
# split to separate image planes and stack vertically ready for OME
_**# it works if I delete this line. The file can be opened in QuPath with no problem**_
**im = pyvips.Image.arrayjoin(im.bandsplit(), across=1)**
im = im.copy()
im.set_type(pyvips.GValue.gint_type, "page-height", image_height)
im.set_type(pyvips.GValue.gstr_type, "image-description",
f"""<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
<Image ID="Image:0">
<!-- Minimum required fields about image dimensions -->
<Pixels DimensionOrder="XYCZT"
ID="Pixels:0"
SizeC="{image_bands}"
SizeT="1"
SizeX="{im.width}"
SizeY="{image_height}"
SizeZ="1"
Type="uint8">
</Pixels>
</Image>
</OME>""")
im.tiffsave(sys.argv[2], compression="jpeg", tile=True,
tile_width=512, tile_height=512,
pyramid=True, subifd=True)
# The save will stop after 2.56 GB with no error, but not complete.
Would you happen to have any idea how to do it? Instead of saving the image first, I prefer to convert it to OEM-TIFF than save it.