我似乎在opencv中找不到一个数据结构,它可以容纳大于8位的像素深度。我的问题是,我想要获取一个LDR图像,并乘以一些像素,使这些像素的值将超过255的边界。到目前为止,这就是我所尝试的。我尝试从0-1映射像素值,而不是0-255,然后用标量乘以它们(以增加它们的值)。但是当我需要再次写图像时,图像是黑暗的,除非我乘以255。我希望你能帮我:)
Mat ApplySunValue(Mat InputImg){
Mat OutPutImg = Mat::zeros(InputImg.rows, InputImg.cols, CV_32FC1);
for(int x = 0; x < OutPutImg.cols; x++){
for(int y = 0; y < OutPutImg.rows; y++){
int PixelValue = InputImg.at<uchar>(y,x)/255.f;
if(PixelValue < 0.9){
OutPutImg.at<uchar>(y,x) = 0;
}else{
OutPutImg.at<uchar>(y,x) = PixelValue * sunMultiplyer;
}
}
}
imwrite("/Users/K******/Desktop/EnviormentMap.jpg", OutPutImg * 255);
namedWindow("Hej", CV_WINDOW_AUTOSIZE);
imshow("Hej", OutPutImg * 255);
return OutPutImg;}
发布于 2014-03-05 10:15:15
这将始终是0(整数除法):
int PixelValue = InputImg.at<uchar>(y,x)/255.f;PixelValue是整数,所以您的比较是BS:
if(PixelValue < 0.9){由于@Micka已经发现,您必须为at()使用正确的类型:
OutPutImg.at<float>(y,x) = 299.0f;
// yes, can be larger than 255 now, so you can discard your broken mapping attempts不能将浮点图像保存或读取为jpeg或png。检查您的opencv库是否带有exr支持:
cerr << cv::getBuildInformation() << endl;如果是这样,则可以将其保存/读取为*.hdr或*.exr。
https://stackoverflow.com/questions/22193624
复制相似问题