Search code examples
c#emgucvfo-dicom

resizing PixelData of DicomData using EmguCV(C#)


i have issue with cv2.resize as you see in the example below. it seems that i use the api in the wrong way, or i missed some declarations. According to the API, the are InputArray, OutPutArray, which I didn't really understand how to use those. I tried the Cv2.Resize as you can see in my code.

Does anyone have a solution how i can use the cv2.resize correctly??. Thnak you.

DicomFile dicomFile_ = DicomFile.Open(pathOfFileList[0],FileReadOption.ReadAll);
//Read Dicom Dataset

var pixelData_ = dicomFile_.Dataset.GetValues<byte>(DicomTag.PixelData);
//Get Pixel Data for each slice 

Mat outputArray = new Mat();

Cv2.Resize(pixelData_.Length, outputArray, new Size(512,512),0.5,0.5, InterpolationFlags.Area);
//I try to resize the pixelData_, which its resolution 1024 pixels*1024 pixels(rows*columns), but it does not work, it seems that im using the cv2.resize in the wrong way.

var t = outputArray.ToBytes();
//i check if the size of the outputarray, which are 1358 bytes!!

enter image description here


Solution

  • You cannot just input the length of the pixeldata array as the input for resize. You need to create a Mat with the correct size and color depth See Create an Image

    If you only need to resize images with a specific color depth (i.e. 16 bit grayscale) I would suggest using the older CV.x 2 Image class. I think this is easier to understand:

    var img = new Image<Gray, ushort>(width, height);
    img.Bytes = source.Data;
    var resizedImage = img.Resize(newWidth, newHeight, Inter.Cubic);
    var resizedBytes = resizedImage.Bytes;