2

ipadのdicomデータからUIImageを取得しようとしています。

コードは次のようになります。

reader->SetFileName(documentsFolderPath/test.dcm);
reader->Update();
ImageType *  imageTest = reader->GetOutput(); // get 2d image data
PixelType * pixelData = imageTest->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<const UInt8*>(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;

しかし、私の出力画像は次のようになります。

http://www.ettisberger.ch/images/outputImage.png

(塗りつぶすスケールのあるイメージビューでは、サイズは関係ありません)

しかし、背景は黒でなければならず、骨のほとんどのピクセルは多かれ少なかれ白です...

私の失敗を見てくれる人はいますか?

編集: おそらく iPad の 16 ビットが問題になるのでしょうか?

EDIT2:私は解決策を知っています。すべてのピクセルを調べて、0 ~ 255 の unsigned int 値を計算します。コントラストを変更する必要があるため、最大値と最小値は画像全体の最大値と最小値です。それは機能しますが、私の方法では 1 つの uiimage を作成するのに 0.1 ~ 0.2 秒かかります。また、400 個の画像のスタックでは非常に遅く、ユーザーは 1 分間待たなければなりませんでした:/ より良い解決策があるかどうかはわかりません。

    for(int i = 0; i < (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++;
} 
4

2 に答える 2

1

EDIT2が提案したのは、画像にウィンドウレベルとウィンドウ幅を適用しているということです。これは、8ビットより高いものを処理するために必要になることがよくあります。EDIT2の現在の速度を上げるために、以前に一度計算された同様の強度のピクセルのルックアップテーブルをいつでも作成できます。

たとえば、元のピクセルの値は1255であり、ウィンドウレベルとウィンドウ幅の計算で、最終的に出力されるのはおそらく123です(例として、urレベルと幅によって異なります)。次に、元の値が1255の後続のピクセルがどれであっても、自動的に123として認識されます(これにより、時間の節約になります。配列を検索するよりも計算に時間がかかります)。

**参考:max、minはウィンドウ幅とウィンドウレベルに関連付ける必要があります(最も簡単な実装の1つは、max =ウィンドウレベル+(ウィンドウ幅/ 2)、およびmin =ウィンドウレベル-(ウィンドウ幅/ 2)です。または、DICOM標準に従うこともできますが、どの章を忘れたか、Grayscale SoftcopyPresentationStateを試してください。

于 2011-06-01T02:40:38.103 に答える
0

私自身はCGColorSpaceCreateDeviceGrayを使用していませんが、R、G、Bが0〜255ですべて同じであるRGBA値を探している可能性はありますか?その場合は、入力を4コンポーネントのデータ構造に変換する必要があります。16ビット浮動小数点から255文字への移行は、私が提供したように計算できます。

DICOM画像の幅とレベルをJPEGの明るさとコントラストに変換するにはどうすればよいですか?

于 2011-05-27T01:08:12.063 に答える