【发布时间】:2014-08-25 17:35:00
【问题描述】:
我正在尝试读取具有单通道和 16 位深度的 png 图像。随后我在一行上找到像素值:
//read the image data in the file "MyPic.JPG" and store it in 'img'
Mat img = imread("sir.png", CV_LOAD_IMAGE_ANYDEPTH);
//Iterate through the line along which Intensity profile is required
LineIterator it(img, Point(1,1), Point(20,20), 8);
vector<Vec3b> buf;
for(int i=0; i<it.count; i++)
{
buf.push_back( Vec3b(*it) );
it++;
}
//print pixel value on the selected line
cerr << Mat(buf) << endl;
打印的值总是小于255的编号:
156, 156, 164; 153, 153, 152; 154, 154, 139; 179, 179, 180; 182, 182, 176; 2
208, 167; 144, 144, 163; 204, 204, 206; 180, 180, 187; 174, 174, 170; 150, 1
162; 154, 154, 170; 157, 157, 181; 181, 181, 159; 164, 164, 152; 130, 130, 1
166, 166, 181; 153, 153, 170; 153, 153, 176; 180, 180, 198]
这意味着它实际上是将该图像读取为 8 位而不是 16 位。
我在 MATLAB 中验证了我的图像,我可以看到对 16 位有效的值,例如:
d=imread('sir.png');
buf = improfile( d, [1 20], [1 20] )
它给出的输出如:
65535 40092 39321 39578 46003 46774 53456 37008 52428 46260 44718 38550 39578 40349 46517 42148 33410 42662 39321 39321
为什么我在 opencv 中的结果与实际不同?如何正确读取图像以使其显示 16 位值?
更新
根据 Roger 的回答,我更新了如下代码:
LineIterator it(img, Point(1,1), Point(20,20), 8);
vector<ushort> buf;
for(int i = 0; i < it.count; i++)
{
buf.push_back(img.at<ushort>(it.pos()));
}
cerr << Mat(buf) << endl;
但现在我的所有像素值都变为 40092,与 MATLAB 输出相比,这是错误的。
【问题讨论】:
标签: image opencv image-processing png