0

画像を IPL_DEPTH_8U から IPL_DEPTH_32S に変換するにはどうすればよいですか?

ウォーターシェッド関数を使用する必要があり、IPL_DEPTH_8U にマーカー イメージがあります。問題は、watershed 関数がマーカーとして IPL_DEPTH_32S のみを受け入れることです。

前もって感謝します、

4

3 に答える 3

1

Mat次の代わりに使用しますIplImagemarker_img.convertTo(marker_img,CV_32S);

IplImage を使用する場合は、最初に画像をスケーリングしてから変換する必要があります。

于 2013-02-26T13:54:46.733 に答える
0

新しい cv::Mat バージョンを使用したくない場合は、次のことを試すことができます。

 IplImage* converted = cvCreateImage(cvSize(img->width,img->heigth),IPL_DEPTH_32S);

 for (int i = 0;i<img->heigth;i++)
     for(int j = 0;j<img-width;j++)
         ((signed long*)(converted->imageData+i*converted->widthStep))[j] = ((unsigned char*)(img->imageData+i*img->widthStep))[j]

3 チャンネルの画像がある場合は!!!!!!!!! 次を使用する必要があります:

 IplImage* converted = cvCreateImage(cvSize(img->width,img->heigth),IPL_DEPTH_32S,3);

 for (int i = 0;i<img->heigth;i++)
     for(int j = 0;j<3*(img-width);j++)//since you have 3 channels
         ((signed long*)(converted->imageData+i*converted->widthStep))[j] = ((unsigned char*)(img->imageData+i*img->widthStep))[j]

コードを書くためのより良い教訓的な方法:

     for (int i = 0;i<img->heigth;i++)
         for(int j = 0;j<(img-width);j++)
{
             ((signed long*)(converted->imageData+i*converted->widthStep))[j*3] = ((unsigned char*)(img->imageData+i*img->widthStep))[j*3]//R or B ??
             ((signed long*)(converted->imageData+i*converted->widthStep))[j*3+1] = ((unsigned char*)(img->imageData+i*img->widthStep))[j*3+1]//G
             ((signed long*)(converted->imageData+i*converted->widthStep))[j*3+2] = ((unsigned char*)(img->imageData+i*img->widthStep))[j*3+2]//R or B ??

}
于 2013-02-26T15:08:00.277 に答える
0

明示的なキャストを使用して、チャネルごとにピクセルごとに手動で行います。

Img32s->imageData[y*((int)Img32s->widthStep)+x*3+C]=(int)((uchar*)Img8u->imageData)[y*((int)Img8u->widthStep)+x*3+C]/255.;
于 2013-02-26T15:40:01.613 に答える