Skip to content
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

Utils function for read/write value from unprocessed data #306

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ducquangkstn
Copy link
Contributor

Rationale:

  • According to this issue readNativeFrames Performance Optimizations #161, we have OOM issues and it happens when the DICOM is about 784Mb and server memory is 16Gb, and the DICOM contains multiple frames.
  • Reason 1: the pixel data is always int (64 bits - 8 bytes), even the bitAllocated can be 16 bit, which means this can takes up to 4 times of memory
  • Reason 2: the way the DICOM library storing data is [[[sample for sample in pixel] for pixel in frame] for frame in image]. B/c the number of pixel per frame is usually 1M (1000 * 1000 image) and sample per pixel can be 1 => this structure takes 4x of memory.
  • Anyway to change this issue direcly from the library will make a breaking change to end users.

Solution:

  • Thanks for contributors, we now have an option to skip processing data and the value of pixel data will be stored in byte array. It is called raw data or unprocessing data.
  • Instead of loading and manipulating the loaded 3-dimension data, we modify the data directly this unprocessed pixeldata. It can be called in-place read/write
  • This is an experimental MR. Just let me know what do you think about the interface.

Copy link
Owner

@suyashkumar suyashkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Had a couple questions in the comments below. Is the main way this saves memory by only loading one frame at a time into the larger ints?

In general, having utilities for folks to work with the unprocessed pixel data after parsing does seem reasonable to me. That said, I wonder if we can potentially share some of the existing code to read native pixel data... will take a closer look next week or the following weekend to see if I can give a more direct suggestion. Thanks!

pkg/frame/inplace/pixeldata_info.go Show resolved Hide resolved
for _, tc := range cases {
t.Run(tc.Name, func(t *testing.T) {
var filesOut bytes.Buffer
require.NoError(t, dicom.Write(io.Writer(&filesOut), tc.existingData))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's not use require/assert, and instead just use Go code to do comparisons, see https://google.github.io/styleguide/go/decisions#assert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed at 16701fa

// ReadUnprocessedValueData read the value of Dicom image directly
// from the byte array of PixelData.UnprocessedValueData with given frame ID.
// This ease the memory usage of reading DICOM image.
func ReadUnprocessedValueData(info *PixelDataMetadata, unprocessedValueData []byte, frameIndex int) ([][]int, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this returns [][]int, this will still have the same issue of expanding the memory from the smaller int to the 64-bit int right? Is the main place this saves memory in the fact that it only does one frame at a time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the main place this saves memory in the fact that it only does one frame at a time

Yes, most of the DICOM with the issues contains multiple frames.

But, I think I would change to a new structure of storing data.

B/c users need to adapt to new way of read/write pixel data anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed at 16701fa

@ducquangkstn ducquangkstn requested a review from suyashkumar May 28, 2024 04:48
@suyashkumar
Copy link
Owner

suyashkumar commented Aug 13, 2024

@ducquangkstn Do you feel that #315 addresses this sufficiently? This makes a bit more of an API change, including using smaller system ints where needed. Thanks again for the support!

@ducquangkstn
Copy link
Contributor Author

@ducquangkstn Do you feel that #315 addresses this sufficiently? This makes a bit more of an API change, including using smaller system ints where needed. Thanks again for the support!

Ok, I would check out the new API

@suyashkumar
Copy link
Owner

Hi @ducquangkstn did you have a chance to peek at the new API?

@ducquangkstn
Copy link
Contributor Author

Hi @ducquangkstn did you have a chance to peek at the new API?

Hi @suyashkumar, sorry for late response, I am recently busy with my company's internal development.

I took a glimpse at your MR and raised few questions.

@suyashkumar
Copy link
Owner

@ducquangkstn no worries at all, thanks for the comments! Sent some first pass responses as well. Thanks!

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.

2 participants