How To Threshold Raw Byte Image with EmguCV

162 Views Asked by At

i am trying to Threshold and also applying the Gaussian Blur on Raw byte image in EmguCV. I have raw array bytes, which are bytes from Dicomfile, i read those bytes and store them in a empty image, once i wanna apply threshold or gaussian blur i get these Exception:

OpenCv: src.type() == CV_8UC1.

Thank you.

var pixelData_ = dataset.GetValues<byte>(DicomTag.PixelData);

var splitPixelSpacing = pixelSpacing.Split('\\');
            
var IPP = dataset.GetString(DicomTag.ImagePositionPatient);

var iimg = new Image<Gray, ushort>(cols, rows);
            
var parse = float.Parse(splitPixelSpacing[0], CultureInfo.InvariantCulture.NumberFormat);

var newPixelSpacing =  parse* (cols / 512);
            
iimg.Bytes = pixelData_;

iimg = iimg.Resize(512, 512, Inter.Area);

var imgBin = new Image<Gray, byte>(512, 512, new Gray(10));

var blr = iimg.ThresholdAdaptive(new Gray(100),
                AdaptiveThresholdType.GaussianC,
                ThresholdType.ToZero,
               5,
                new Gray(2));
//I set here a breakpoint then i get these Exception:src.type() == CV_8UC1.

1

There are 1 best solutions below

0
On

Unfortenatly the documentation of EmguCV lacks any information about this error, and also lack any prerequisites. But emguCV is just a wrapper around OpenCV, and if we check that documentation we can find:

src Source 8-bit single-channel image.

I.e. ThresholdAdaptive is limited to 8 bit grayscale and will not work for 16 bit grayscale images.

If you just want a simple threshold you might want to use ThresholdBinary, or one of the other simple thresholding methods.