Im trying to increase the sharpness of an image using EmguCV
Image<Bgr, Byte> myImage = new Image<Bgr, Byte>(new Bitmap(pictureBox1.Image));
float[,] matrixKernel = new float[3, 3] {
{ 0,-1, 0 },
{-1, 5,-1 },
{ 0,-1, 0 }
};
ConvolutionKernelF matrix = new ConvolutionKernelF(matrixKernel);
Image<Bgr, float> result = myImage.Convolution(matrix);
Image<Bgr, Byte> BGRResult = result.ConvertScale<byte>(1, 0);
e.Result = BGRResult.ToBitmap();
myImage.Dispose();
result.Dispose();
BGRResult.Dispose();
The code works fine for medium resolution images,but when using high resolution images eg: 6000X4000 The following exception is thrown
Note that the sharpening works fine even for high resolution images when the project is set to AnyCPU -> Debug Mode I'm using EmguCV 3.3
Update:
As per Rick's reference answer,i made the following modification,but the issue persists.Please advice.
float[,] matrixKernel = new float[3, 3] {
{ 0,-1, 0 },
{-1, 5,-1 },
{ 0,-1, 0 }
};
ConvolutionKernelF matrix = new ConvolutionKernelF(matrixKernel);
var result2 = myImage.CopyBlank();
var handle = GCHandle.Alloc(result2);
Image<Bgr, float> result = result2.Convolution(matrix);
Image<Bgr, Byte> BGRResult = result.ConvertScale<byte>(1, 0);
bm_dest = new Bitmap(BGRResult.ToBitmap());
handle.Free();
BGRResult.Dispose();
result.Dispose();
myImage.Dispose();
matrix.Dispose();