Skip to content

feat(Zarr): Identify RGB RGBA pixel types #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/IO/ZarrMultiscaleSpatialImage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PixelTypes } from 'itk-wasm'
import { IntTypes, PixelTypes } from 'itk-wasm'

import MultiscaleSpatialImage from './MultiscaleSpatialImage'
import bloscZarrDecompress from '../Compression/bloscZarrDecompress'
Expand Down Expand Up @@ -147,13 +147,33 @@ const extractScaleSpacing = async dataSource => {

const components = info.arrayShape.get('c') ?? 1

const componentType = getComponentType(info.pixelArrayMetadata.dtype)

let pixelType = PixelTypes.Scalar
if (components !== 1) {
if (
components === 3 &&
!info.arrayShape.has('z') &&
componentType === IntTypes.Uint8
) {
pixelType = PixelTypes.RGB
} else if (
components === 4 &&
!info.arrayShape.has('z') &&
componentType === IntTypes.Uint8
) {
pixelType = PixelTypes.RGBA
} else {
pixelType = PixelTypes.VariableLengthVector
}
}

const imageType = {
// How many spatial dimensions? Count greater than 1, X Y Z elements because "axis" metadata not defined in ngff V0.1
dimension: ['x', 'y', 'z'].filter(dim => info.arrayShape.get(dim) > 1)
.length,
pixelType:
components === 1 ? PixelTypes.Scalar : PixelTypes.VariableLengthVector,
componentType: getComponentType(info.pixelArrayMetadata.dtype),
pixelType,
componentType,
components,
}

Expand Down