Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Image<Gray, Byte> to Image<Gray, float>?

Tags:

c#

emgucv

I'm trying to substract 1 image from another, somewhat like this:

Image<Gray, float> result, secondImage;
Image<Gray, byte> firstImage;
result = firstImage - secondImage;

But it gives an error

Operator '-' cannot be applied to operands of type 'Emgu.CV.Image<Emgu.CV.Structure.Gray,byte>' and 'Emgu.CV.Image<Emgu.CV.Structure.Gray,float>'

Maybe i need to convert firstImage into Image<Gray, float> type. But I don't know how to do it.

like image 633
maru1414152 Avatar asked May 24 '12 05:05

maru1414152


1 Answers

To quote from the documentation:

Color and Depth Conversion

Converting an Image between different colors and depths are simple. For example, if you have Image img1 and you wants to convert it to a grayscale image of Single, all you need to do is

Image<Gray, Single> img2 = img1.Convert<Gray, Single>();

So, in your case, you could use

result = firstImage.Convert<Gray, float>() - secondImage;
like image 124
Heinzi Avatar answered Oct 21 '22 07:10

Heinzi