我使用Python2.7,OpenCV,matplotlib来创建图像转换的“联系人表”。我的输入文件是~1920x1200 16位灰度PNG。我想保存完整的联系人表单(如果我理解正确的话,可以用'fig‘对象来表示代码)。
当我运行以下命令时,我得到一个~200kb的输出PNG,它对图像查看器来说是空白的。我不确定是否正确地使用了savefig() (或者是在正确的对象上),或者问题是否在于savefig被16位数据搞混了
很抱歉写了这么多麻烦的代码!
编辑:示例http://www.filedropper.com/sample_83
fig,axs = plt.subplots(5,3)
for clip in enumerate(range(1,6)):
for exp in enumerate(range(2,5)):
gridsize = (pow(2,exp[1]),pow(2,exp[1]))
cliplim = clip[1]*3
clahe = cv.createCLAHE(clipLimit=cliplim,tileGridSize=gridsize)
cl = cv.normalize(clahe.apply(img16),None,0,65535,cv.NORM_MINMAX)
axs[clip[0],exp[0]].imshow(cv.bitwise_not(cl),cmap='Greys')
axs[clip[0],exp[0]].set_title('clip=%s grid=%s'%(cliplim,gridsize[0]))
axs[clip[0],exp[0]].get_xaxis().set_visible(False)
axs[clip[0],exp[0]].get_yaxis().set_visible(False)
fig.savefig('out.png')
plt.show()发布于 2020-02-28 16:33:32
你的图像确实是16位的,但它的对比度很低,这就是为什么它看起来是“扁平灰色”的原因。您可以像这样通过ImageMagick identify运行它。我在右边添加了指向突出部分的箭头。
magick identify -verbose sample.png # omit "magick" if still using v6示例输出
Image: sample.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 1920x1080+0+0
Units: Undefined
Colorspace: Gray
Type: Grayscale
Base type: Undefined
Endianess: Undefined
Depth: 16-bit <--- 16-bit
Channel depth:
Gray: 16-bit
Channel statistics:
Pixels: 2073600
Gray:
min: 27916 (0.425971) <--- min 27,916 of 65,535
max: 44722 (0.682414) <--- max 44,722 of 65,535
mean: 30629.2 (0.467372)
standard deviation: 297.459 (0.00453893)
kurtosis: 219.144
skewness: 6.43389
entropy: 0.811496
Rendering intent: Undefined
Gamma: 0.454545
Matte color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1920x1080+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2020-02-28T08:17:02+00:00
date:modify: 2020-02-28T08:17:01+00:00
png:IHDR.bit-depth-orig: 16
png:IHDR.bit_depth: 16
png:IHDR.color-type-orig: 0
png:IHDR.color_type: 0 (Grayscale)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 1920, 1080
signature: bfd36a4055d8bb31695bbed19738063efd9e842d4beec01c5d5123d32f1df42f
Artifacts:
verbose: true
Tainted: False
Filesize: 3.96262MiB
Number pixels: 2073600
Pixels per second: 75.0272MP
User time: 0.020u
Elapsed time: 0:01.027
Version: ImageMagick 7.0.9-6 Q16 x86_64 2019-11-27 https://imagemagick.org如您所见,在65,535的可能范围内,亮度范围从27,916到44,722,因此您在16位图像中仅使用了可用范围的26%。
因此,如果你想让你的图像显示得更好,你可能想先把它规格化到全范围。
https://stackoverflow.com/questions/60440859
复制相似问题