Note that there are some explanatory texts on larger screens.

plurals
  1. PODicom Pixeldata to UIImage
    primarykey
    data
    text
    <p>Im trying to get a UIImage out of my dicom data on the ipad.</p> <p>The Code looks like that:</p> <pre><code>reader-&gt;SetFileName(documentsFolderPath/test.dcm); reader-&gt;Update(); ImageType * imageTest = reader-&gt;GetOutput(); // get 2d image data PixelType * pixelData = imageTest-&gt;GetBufferPointer(); const void* buffer = pixelData; // Set the dimensions of the current context size_t width = 157; // set manually, but correct size_t height = 143; // 1 byte per component size_t bitsPerComponent = 8; unsigned int multiplier; bitsPerComponent *= 2; // short = 2 byte size_t bitsPerPixel, bytesPerRow; CGColorSpaceRef colorSpace; CGBitmapInfo bitmapInfo; CGDataProviderRef theDataProvider; CFDataRef theDataReference; bool shouldInterpolate = NO; CGColorRenderingIntent theIntent; bitsPerPixel = bitsPerComponent * 1; // because of grayscale image colorSpace = CGColorSpaceCreateDeviceGray(); bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrder32Big; // cg data provider to build the cg image const UInt8* rawData = static_cast&lt;const UInt8*&gt;(buffer); // For some reason initiating a CGImage uses BITS per pixel, so we need to divide by 8 to get BYTES // per pixel bytesPerRow = (bitsPerPixel/8) * width; theDataReference = CFDataCreate(NULL, rawData, (bytesPerRow*height)); theDataProvider = CGDataProviderCreateWithCFData(theDataReference); // Finally create the image reference CGImageRef theImageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, bitmapInfo, theDataProvider, nil, shouldInterpolate, theIntent); // Construct an output image UIImage *myImage = [UIImage imageWithCGImage:(theImageRef)]; imageView.image = myImage; </code></pre> <p>But my output image then looks like that:</p> <p><a href="http://www.ettisberger.ch/images/outputImage.png" rel="nofollow">http://www.ettisberger.ch/images/outputImage.png</a></p> <p>(on a imageview with scale to fill, so the size doesnt matter)</p> <p>But the background should be black and the most pixel of the bone are more or less white...</p> <p>Is there someone who can see my fail?</p> <p>EDIT: Could perhaps the 16bit on the ipad be a problem?</p> <p>EDIT2: I got a solution know. I go through every pixel and calculate a unsigned int value between 0 and 255. The max and min are the max and the min value of the whole picture, because we need to change the contrast. It works, but my method needs 0.1-0.2 seconds to create one uiimage - and with a stack of 400 images its so slow and the user had to wait for 1 minute :/ Dont know if there is a better solution.</p> <pre><code> for(int i = 0; i &lt; (bytesPerRow*height);i++){ short tmpPixelValue = *pixelData; short tmpNewPixelValue; if(tmpPixelValue == 0){ tmpNewPixelValue = 0; }else{ tmpNewPixelValue = (tmpPixelValue - min) * (255.0 / (max - min)); } pixelBuffer[i] = (UInt8)tmpNewPixelValue; pixelData++; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload