Repository navigation
feat(stack): add nansen.stack.crop to crop and export image stacks - #139
Merged
Merged
Conversation
nansen.stack.crop(imageStack, rect) crops every frame of an ImageStack to the rectangle [xmin, ymin, width, height] and returns a new ImageStack. The output has exactly height rows and width columns. All channels, planes and timepoints are kept, along with the dimension arrangement and the metadata that stays valid for a cropped stack. With FilePath, the cropped data is written to a binary (.raw) or TIFF file, and a virtual ImageStack for that file is returned. Data is read and written in chunks along the time or plane dimension, and only the cropped region is requested from the source, so a stack larger than memory can be cropped to a binary file. Existing files are never written to. The function errors if the target file exists. It also errors if the TIFF adapter resolves the new file path to a numbered series of TIFF files that already exists in the folder, because writes would otherwise go into those files. Metadata is copied property by property, because StackMetadata.updateFromSource clears StartTime on the source metadata object. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
TSM.readData subtracted the full dark frame from the requested data. A read cropped along x or y failed with an incompatible sizes error, because the sizes differ. A read of a single row or column did not fail, but was implicitly expanded to the full frame size. The dark frame is now indexed with the same x and y subscripts as the image data. nansen.stack.crop depends on this, because it requests only the cropped region from the source. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
nansen.stack.crop, the image stack counterpart ofimcrop. It crops every frame of anImageStackto a rectangle and returns a newImageStack. WithFilePath, the cropped data is written to a new file and a virtualImageStackfor that file is returned. Adds a unit test class for the function.rectis[xmin, ymin, width, height]in pixel indices, and the output has exactlyheightrows andwidthcolumns. A rectangle that extends outside the image is an error.ChunkLengthoverrides the default chunk size, which is chosen from the available memory.FilePath, the cropped stack is returned in memory. WithFilePath, the extension selects the format: binary (.raw) or TIFF (.tif,.tiff), which are the formatsnansen.stack.opencan create.TiffMultiPartresolves the new path to a numbered series of TIFF files that already exists in the folder, because writes would otherwise go into those files.Also fixes cropped reads in the TSM adapter.
TSM.readDatasubtracted the full dark frame from the requested data. A read cropped along x or y failed with an incompatible sizes error, and a read of a single row or column was implicitly expanded to the full frame size. The dark frame is now indexed with the same x and y subscripts as the image data.nansen.stack.cropdepends on this, because it requests only the cropped region.Metadata is copied property by property, because
StackMetadata.updateFromSourceclearsStartTimeon the source metadata object. That bug is left as is here.The tests that create
.rawfiles are expected to fail on the Linux runner. From reading the code,Binary.initializeFileassignsstatusonly on Windows and macOS, so creating a binary stack errors on Linux. The fix is a one-line change inBinary.mand is not part of this PR.🤖 Generated with Claude Code