Skip to content

Support RGB native frames in GetImage - #386

Open
ChrisJr404 wants to merge 1 commit into
suyashkumar:mainfrom
ChrisJr404:rgb-native-frame-image
Open

Support RGB native frames in GetImage#386
ChrisJr404 wants to merge 1 commit into
suyashkumar:mainfrom
ChrisJr404:rgb-native-frame-image

Conversation

@ChrisJr404

Copy link
Copy Markdown

This adds RGB support to NativeFrame.GetImage as requested in #336, so color native images can be turned into a Go image instead of erroring out.

Right now GetImage only handles frames with a single sample per pixel and returns ErrUnsupportedSamplesPerPixel for everything else, so anything with color just fails. Following your pointer in the issue, a frame with 3 samples per pixel is now treated as RGB: it reads the interleaved R, G, B samples for each pixel (the same layout GetPixel/GetSample already assume) and builds an image.RGBA64, using uint16 channels the way the grayscale path already casts into image.Gray16. Grayscale frames are untouched and still come back as image.Gray16, and other sample counts keep returning ErrUnsupportedSamplesPerPixel.

Since the samples are read straight through without scaling, this matches the existing "basic, does not autoscale" behavior of the grayscale path rather than adding any window/level handling. Planar configuration (all R, then all G, then all B) isn't handled here — it would need to be dealt with at parse time — so this sticks to the interleaved layout that's assumed elsewhere in the frame.

dicomutil already encodes whatever GetImage returns with png.Encode, so it now writes color PNGs for RGB native frames without any change. I added table tests covering the RGB path alongside the existing grayscale ones.

Closes #336

GetImage only handled single-sample (grayscale) frames and returned
ErrUnsupportedSamplesPerPixel for anything else. Frames with 3 samples
per pixel are now rendered as an image.RGBA64 by reading the interleaved
R, G, B samples for each pixel, while grayscale frames keep returning an
image.Gray16 exactly as before.

Fixes suyashkumar#336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for RGB for pixeldata

1 participant