I have a medical image that I’m reading from a binary (DICOM) file. Example code:
[code]’ data is a Xojo.Core.MemoryBlock containing the raw pixel information
’ transformedData results from applying a calculation to the rawValue to convert the
’ stored pixel data to a non-manufacturer dependent value
’ winCentre and winWidth are thresholds that constrain the pixel value after transformation
#pragma BackgroundTasks False
image = new Picture(columns, rows)
surface = image.RGBSurface
for row = 0 to maxRows
for col = 0 to maxCols
rawValue = data.Int16Value(offset)
’ Apply the rescale slope and intercept transformation
transformedValue = (rescaleSlope * rawValue) + rescaleIntercept
’ Apply the windowing levels to the transformed pixel value
surface.pixel(col, row) = ColourAfterWindowing(transformedValue, winCentre, winWidth)
offset = offset + 2
next col
next row[/code]
This correctly creates the image I need but there are a couple of issues:
1). It takes about 200 ms to create a 512x512 image. About 100 ms of this is a result of the code in ColourAfterWindowing(). The code for this is below. Putting the code inline (i.e. not a separate function call) doesn’t seem to reduce the time to create the image significantly:
[code]sub ColourAfterWindowing(inputValue as Double, centre as Double, width as Double) as Color
#pragma BackgroundTasks False
dim value as Double
if (inputValue <= centre - 0.5 - (width - 1)/2) then
value = 0
elseif (inputValue > centre - 0.5 + (width - 1)/2) then
value = 1
else
value = ((inputValue - (centre - 0.5)) / (width - 1) + 0.5)
end if
return HSV(0, 0, value)
end sub[/code]
2). One of the key operations needed when viewing medical images is the ability to “re-window” in realtime. Essentially, this means adjusting the pixel value of the pixels in the image to be within a certain threshold. Unless I can think of a clever way, this would require me to re-run the loop everytime the user wanted to adjust the window (usually done by holding down the mouse button and moving the mouse over the image). There’s no way that would be usable if it took 200 ms for every re-windowing adjustment.
Does anyone have any suggestions as to how I can alter the pixel values more quickly? I feel like I have grabbed the low-lying fruit already with #pragma BackgroundTasks False and using the RGBSurface.
I don’t want to use a plugin and it needs to work on all Xojo platforms. This will be an open source library when complete.
Thanks,