我正在通過scipy.misc
模塊(imread,imresize,imsave函數)對屏幕截圖(PNG格式)進行大小調整並將其寫回TIF格式。 TIF格式圖像將被輸入到Tesseract-OCR中。但是,Tesseract抱怨TIF文件的元數據中指定的dpi是0。如何通過scipy.misc.imsave
或任何其他方法保存圖像時指定此項?如何通過scipy.misc.imsave將圖像保存爲tif時指定dpi?
1
A
回答
1
請把這個下「任何其他方法」 :-)
你可以exiftool
這樣設置分辨率:
exiftool SomeImage.tif -xresolution=300 -yresolution=300 -resolutionunit=inches
與ImageMagick的一下:
identify -verbose SomeImage.tif
Image: SomeImage.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 100x100+0+0
Resolution: 300x300
Print size: 0.333333x0.333333
...
...
我建議你用shell來運行這個命令,並使用os.system()
。
A Python wrapper存在,但我從來沒有使用過它,不能擔保。
2
沒有分析您的問題究竟從何而來,the approach of Mark(也許這足以讓你,也許不是,我能想象有別的代碼中的一些東西,可能是這個原因),可以通過使用Pillow(和我不要效仿在scipy的包裝中沒有看到這個選項)。
實際上,我們不是像他那樣重寫標籤,而是在做原始任務時關注這些標籤。在實踐中,兩種方法都應該沒問題。
scipy的概率很高,已經爲using Pillow under the hood(Note that Pillow (https://python-pillow.org/) is not a dependency of SciPy, but the image manipulation functions indicated in the list below are not available without it.
;此列表包含imsave
)。
from scipy.misc import ascent # test image
import PIL.Image
scipy_img = ascent().astype('uint8')
arr2im = PIL.Image.fromarray(scipy_img)
arr2im.save('test.tif', format='TIFF',
dpi=(100., 100.), # there still seems to be a bug when using int's here
compression='tiff_lzw',)
與exiftool檢查:
ExifTool Version Number : 10.63
File Name : test.tif
...
Image Width : 512
Image Height : 512
Bits Per Sample : 8
Compression : LZW
...
X Resolution : 100
Y Resolution : 100
...
Resolution Unit : inches
Image Size : 512x512
Megapixels : 0.262
相關問題
- 1. 如何通過在fileupload期間轉換成jpg保存tif格式的圖像?
- 2. 如何在Android中將位圖保存到位圖時設置dpi圖像?
- 3. 如何將圖像保存爲圖像
- 4. 保存枕頭圖像時如何正確設置DPI?
- 5. 使用枕頭獲取圖像的dpi爲tif文件
- 6. 如何通過PHP保存圖像?
- 7. 將圖像保存到指定位置
- 8. 如何通過圖像繪製圖像並將其保存爲android系統
- 9. Flex - 用更高的dpi保存圖像
- 10. 通過webView保存圖像..?
- 11. 將原始數據保存爲tif
- 12. 如何將圖像從drawView保存到指定的文件夾
- 13. 如何處理.tif圖像?
- 14. 如何將圖像保存爲流?
- 15. 如何將畫布保存爲圖像?
- 16. 如何將此圖像保存爲HD?
- 17. 如何將ImageView保存爲圖像?
- 18. 如何將tkinter表保存爲圖像
- 19. 如何將圖像保存爲RelativeLayout
- 20. 如何將圖像保存爲DICOM
- 21. EmguCV - 如何在保存圖像時指定JPEG質量?
- 22. 保存圖像爲.tif沒有Libtiff [編輯]
- 23. 如何通過HttpConnection將圖像保存到黑莓設備?
- 24. 如何通過url將圖像保存到目錄
- 25. 如何通過Hibernate將圖像保存到SQLite數據庫?
- 26. 如何通過JavaScript將圖像保存在Parse.com中?
- 27. 將Dicom圖像導出爲tif格式
- 28. 如何將實時地圖保存爲圖像?
- 29. 如何將JPanel作爲圖像保存爲不可見時?
- 30. 雙穩態圖像爲TIF