[英]How to visualize a 16-bit grayscale image with cv2.imshow()?
I have a set of grayscale drone images in tiff
format having 16-bit resolution where a person can be seen moving.我有一组
tiff
格式的灰度无人机图像,具有 16 位分辨率,可以看到一个人在移动。 How can I visualize these images in OpenCV as a normal image, so that I can see the information within the image in OpenCV?如何在 OpenCV 中将这些图像可视化为普通图像,以便我可以在 OpenCV 中查看图像中的信息? Currently, when I try to read and show the image, I see a black image.
目前,当我尝试阅读和显示图像时,我看到的是黑色图像。
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
args = vars(ap.parse_args())
image = cv2.imread(args["image"],IMREAD_ANYCOLOR | IMREAD_ANYDEPTH)
cv2.imshow("image", image)
cv2.waitKey(0)
I have tried the above code, but it still displays a complete black image.我已经尝试了上面的代码,但它仍然显示一个完整的黑色图像。 However, when I convert the image to a
png
and then use the above code, then it works fine which I do not want to do due to loss of information.但是,当我将图像转换为
png
然后使用上面的代码时,它可以正常工作,由于信息丢失,我不想这样做。
Here is the link to sample image.这是示例图像的链接。 All images contain different information.
所有图像都包含不同的信息。
https://filebin.net/n3oidsqn70eq8a9x/gelmer_gas_0_Raw_316_4245_2942_1455208775.tif?t=c2m8vnsn https://filebin.net/n3oidsqn70eq8a9x/gelmer_gas_0_Raw_316_4245_2942_1455208775.tif?t=c2m8vnsn
The image should be like the below.图像应如下所示。 This was opened with another software just for visual purpose
这是用另一个软件打开的,只是为了视觉目的
As you stated before, loading is easy:正如您之前所说,加载很容易:
img = cv2.imread("a.tif", cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
Then, one has different options to visualize a thermal image.然后,人们有不同的选择来可视化热图像。 The simple naive approach is to normalize from the min to the max value:
简单天真的方法是从最小值归一化到最大值:
normed = cv2.normalize(img, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U)
After, you can color it with a colormap:之后,您可以使用颜色图为它着色:
color = cv2.applyColorMap(normed, cv2.COLORMAP_JET)
My suggestion would be to fix the temperature range and clip the rest of the values to get an image with colors that can be compare between several images or video.我的建议是修复温度范围并剪辑其余的值,以获得可以在多个图像或视频之间进行比较的颜色的图像。 To do that, you can take the idea from this answer assuming your new min and max are 0 and 255 and your old min and max are the range you need.
为此,您可以从这个答案中获取想法,假设您的新最小值和最大值分别为 0 和 255,而旧的最小值和最大值是您需要的范围。
To be more specific, in your case you need something like:更具体地说,在您的情况下,您需要以下内容:
def normalizeImg(low, high, img):
imgClip = np.clip(img, low, high)
maxVal = np.max(imgClip)
minVal = np.min(imgClip)
return np.uint8((255.)/(maxVal-minVal)*(imgClip-maxVal)+255.)
Where low and high are the raw values you want to normalize to.低和高是您想要标准化的原始值。 And then you use it like:
然后你像这样使用它:
def celsiusToPixel(val):
return (val + 273.15) / 0.04
rangeToUse = [celsiusToPixel(20), celsiusToPixel(30)] # from 20-30° celsius
normed_range = normalizeImg(rangeToUse[0], rangeToUse[1], img)
I hope a didn't miss anything, but if you have questions, just ask :)我希望没有遗漏任何东西,但是如果您有任何疑问,请提问:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.