2012-05-24 147 views
4

我試圖從另一個1個。減去形象,有點像這樣:如何把Image <Gray, Byte>轉換成Image <Gray, float>?

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

但它給出了一個錯誤

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>' 

也許我需要firstImage轉換成Image<Gray, float>類型。但我不知道該怎麼做。

回答

7

要從the documentation引述如下:

顏色和深度轉換

是簡單的不同的顏色和深度之間轉換圖像。例如,如果您有影像IMG1,你想將其轉換爲單灰度圖像,所有你需要做的是

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

所以,你的情況,你可以使用

result = firstImage.Convert<Gray, float>() - secondImage; 
+2

免責聲明:我從來沒有見過或使用過emgucv,只需通過Google搜索和閱讀得到這個答案。 (是的,這是一個「你也可以這樣做!」推動。) – Heinzi

+0

謝謝你張貼這個。你是一個偉大的男人(或女人)。 –

+1

@Heinzi ...現在這是谷歌的第一個搜索結果的問題! – geometrikal