2017-01-06 106 views
0

我能夠使用imebra加載dicom圖像,並且想要更改圖像的顏色,但無法找出方法。我想在Dicomite應用程序中實現功能。Imebra - 更改顏色對比

以下是我的代碼:

public void loadDCM() { 

    com.imebra.DataSet loadedDataSet = com.imebra.CodecFactory.load(dicomPath.getPath()); 

    com.imebra.VOIs voi = loadedDataSet.getVOIs(); 

    com.imebra.Image image = loadedDataSet.getImageApplyModalityTransform(0); 
    //  com.imebra.Image image = loadedDataSet.getImage(0); 
    String colorSpace = image.getColorSpace(); 


    long width = image.getWidth(); 
    long height = image.getHeight(); 

    TransformsChain transformsChain = new TransformsChain(); 
    com.imebra.DrawBitmap drawBitmap = new com.imebra.DrawBitmap(transformsChain); 


    com.imebra.TransformsChain chain = new com.imebra.TransformsChain(); 
    if (com.imebra.ColorTransformsFactory.isMonochrome(image.getColorSpace())) { 
    // Allocate a VOILUT transform. If the DataSet does not contain any pre-defined 
    // settings then we will find the optimal ones. 
    VOILUT voilutTransform = new VOILUT(); 

    // Retrieve the VOIs (center/width pairs) 
    com.imebra.VOIs vois = loadedDataSet.getVOIs(); 

    // Retrieve the LUTs 
    List <LUT> luts = new ArrayList <LUT>(); 
    for (long scanLUTs = 0;; scanLUTs++) { 
    try { 
    luts.add(loadedDataSet.getLUT(new com.imebra.TagId(0x0028, 0x3010), scanLUTs)); 
    } catch (Exception e) { 
    break; 
    } 
    } 

    if (!vois.isEmpty()) { 
    voilutTransform.setCenterWidth(vois.get(0).getCenter(), vois.get(0).getWidth()); 
    } else if (!luts.isEmpty()) { 
    voilutTransform.setLUT(luts.get(0)); 
    } else { 
    voilutTransform.applyOptimalVOI(image, 0, 0, width, height); 
    } 

    chain.addTransform(voilutTransform); 

    com.imebra.DrawBitmap draw = new com.imebra.DrawBitmap(chain); 

    // Ask for the size of the buffer (in bytes) 

    long requestedBufferSize = draw.getBitmap(image, drawBitmapType_t.drawBitmapRGBA, 4, new byte[0]); 

    byte buffer[] = new byte[(int) requestedBufferSize]; // Ideally you want to reuse this in subsequent calls to getBitmap() 
    ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); 

    // Now fill the buffer with the image data and create a bitmap from it 
    drawBitmap.getBitmap(image, drawBitmapType_t.drawBitmapRGBA, 4, buffer); 
    Bitmap renderBitmap = Bitmap.createBitmap((int) image.getWidth(), (int) image.getHeight(), Bitmap.Config.ARGB_8888); 
    renderBitmap.copyPixelsFromBuffer(byteBuffer); 

    image_view.setImageBitmap(renderBitmap); 

    } 
+0

顯示完整代碼:) –

回答

0

如果你正在處理一個黑白圖像,你要修改的演示亮度/對比度,那麼你就必須修改VOILUT的參數變換(voilutTransform變量你的代碼)。

在計算要顯示的位圖之前,您可以獲取變換應用於圖像的中心和寬度,然後在再次調用drawBitmap.getBitmap之前修改它們。

例如,加倍的對比度:

voilutTransform.setCenterWidth(voilutTransform.getCenter(), voilutTransform.getWidth()/2); 

// Now fill the buffer with the image data and create a bitmap from it 
drawBitmap.getBitmap(image, drawBitmapType_t.drawBitmapRGBA, 4, buffer); 

參見this answer爲繞中心詳情/寬度

+0

沒有在voilutTransform對象命名setWidth()方法 – user7382820

+0

我的不好,方法是setCenterWidth。我已經更新了答案 –

+0

我嘗試更改爲1000,如下所示:voilutTransform.setCenterWidth(voilutTransform.getCenter(),voilutTransform.getWidth()/ 1000); 但沒有改變任何 – user7382820