Is there a way to convert IplImage pointer to float pointer? Basically converting the imagedata to float. Appreciate any help on this.
问问题
5466 次
3 回答
7
使用cvConvert(src,dst)
wheresrc
是源图像,dst
是预分配的浮点图像。
例如
dst = cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_32F,1);
cvConvert(src,dst);
于 2011-06-14T20:40:26.637 回答
1
// Original image gets loaded as IPL_DEPTH_8U
IplImage* colored = cvLoadImage("coins.jpg", CV_LOAD_IMAGE_UNCHANGED);
if (!colored)
{
printf("cvLoadImage failed!\n");
return;
}
// Allocate a new IPL_DEPTH_32F image with the same dimensions as the original
IplImage* img_32f = cvCreateImage(cvGetSize(colored),
IPL_DEPTH_32F,
colored->nChannels);
if (!img_32f)
{
printf("cvCreateImage failed!\n");
return;
}
cvConvertScale(colored, img_32f);
// quantization for 32bit. Without it, this img would not be displayed properly
cvScale(img_32f, img_32f, 1.0/255);
cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
cvShowImage ("test", img_32f);
于 2011-08-10T20:32:03.763 回答
0
您无法通过简单地投射指针将图像转换为浮动。您需要遍历每个像素并计算新值。
请注意,大多数浮点图像类型假定范围为 0-1,因此您需要将每个像素除以您想要的最大值。
于 2011-06-14T20:15:33.147 回答