2011-12-19 11 views
1

Image.InRangeを使用してイメージからマスクを作成しています。パフォーマンスを最大限に保つために、私はImage.ROIを使用して画像をトリミングし、InRangeメソッドを使用する前に使用しています。実際に画像で作業するためには、元の画像と同じ大きさにする必要がありますが、画像を保存する寸法を変更するのではなく、画像を拡大縮小する方法がわかります。ここで 画像サイズ変更<Gray, byte>スケーリングなし。 Emgu CV

は、問題のコードです:
public Image<Gray, byte> Process(Image<Bgr, byte> frameIn, Rectangle roi) 
    { 
     Image<Bgr, byte> rectFrame = null; 
     Image<Gray, byte> mask = null; 
     if (roi != Rectangle.Empty) 
     { 
      rectFrame = frameIn.Copy(roi); 
     } 
     else 
     { 
      rectFrame = frameIn; 
     } 

     if (Equalize) 
     { 
      rectFrame._EqualizeHist(); 
     } 


     mask = rectFrame.InRange(minColor, maxColor); 

     mask ._Erode(Iterations); 
     mask ._Dilate(Iterations); 

     if (roi != Rectangle.Empty) 
     { 
      //How do I give the image its original dimensions? 
     } 

     return mask; 
    } 

ありがとう、 クリス

+0

はあなたが/何をやったかを示すことができた

乾杯は、質問の形でこれを入れて、助け? – JesseBuesking

答えて

1

私はあなたが最も簡単な方法は、マスクをコピーすることですframInと同じサイズでマスクを戻したいと仮定しますframInと同じサイズの新しい画像に変換します。あなたのアプリケーションが時間に敏感でない場合、framInと同じサイズのマスクを作成してROIを設定し、次に操作を行うことができます。これは処理に時間がかかり、ベストプラクティスではありません。

とにかくここにはあなたのコードがありますが、私に知らせていない場合はそれに従って修正します。

if (roi != Rectangle.Empty) 
{ 
    //Create a blank image with the correct size 
    Image<Gray, byte> mask_return = new Image<Gray, byte>(frameIn.Size); 
    //Set its ROI to the same as Mask and in the centre of the image (you may wish to change this) 
    mask_return.ROI = new Rectangle((mask_return.Width - mask.Width)/2, (mask_return.Height - mask.Height)/2, mask.Width, mask.Height); 
    //Copy the mask to the return image 
    CvInvoke.cvCopy(mask, mask_return, IntPtr.Zero); 
    //Reset the return image ROI so it has the same dimensions 
    mask_return.ROI = new Rectangle(0, 0, frameIn.Width, frameIn.Height); 
    //Return the mask_return image instead of the mask 
    return mask_return; 
} 

return mask; 

希望これは

クリス

+0

ありがとう、それは完璧に働いた! –

関連する問題