ImageMagick在转换为JPG时以黑线分割NASA的[.IMG]文件 [英] ImageMagick is splitting the NASA's [.IMG] file by a black line upon converting to JPG

查看:110
本文介绍了ImageMagick在转换为JPG时以黑线分割NASA的[.IMG]文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些原始的.IMG格式文件,我正在使用ImageMagick将其转换为.jpg以应用CNN分类器.但是,转换后的图像有一条黑色的垂直线,将图像分为两部分.该行左侧的部分实际上应该位于图像右侧部分的右侧.我发布了示例图片:

I have some raw .IMG format files which I'm converting to .jpg using ImageMagick to apply a CNN Classifier. The converted images, however have a black vertical line splitting the image into two. The part on the left side of the line should have actually been on the right side of the right part of the image. I've posted a sample image:

我使用了命令magick convert input_filename.IMG output_filename.jpg

原始.IMG文件

以下是图片的外观(使用numpy手动转换):

Here is how the image is supposed to look (converted manually using numpy):

图像的实际外观(使用ImageMagick使用垂直黑线):

How the image is actually looking (with the vertical black line using ImageMagick):

版本详细信息:

harshitjindal@Harshits-MacBook-Pro ~ % magick identify -version
Version: ImageMagick 7.0.10-0 Q16 x86_64 2020-03-08 
https://imagemagick.org Copyright: © 1999-2020 ImageMagick Studio LLC 
License: https://imagemagick.org/script/license.php Features: Cipher DPC     
HDRI Modules OpenMP(3.1)  Delegates (built-in): bzlib freetype heic jng     
jp2 jpeg lcms ltdl lzma openexr png tiff webp xml zlib

推荐答案

我不知道ImageMagick为什么无法正确解释文件,但是我可以向您展示如何使其正常工作.

I don't know why ImageMagick is failing to interpret the file correctly, but I can show you how to make it work.

您需要在文件中搜索图像的高度,宽度和数据类型,您可以这样做:

You need to search in your file for the height, width and data type of your image, you can do that like this:

grep -E "LINES|LINE_SAMPLES|BITS" EW0220149939G.IMG 
LINES              = 1024
LINE_SAMPLES       = 1024
SAMPLE_BITS        = 8

这意味着您的图像为1024x1024和8位/样本(1字节).然后,您需要从文件尾部获取一定数量的字节,并将其输入ImageMagick.因此,您需要最后的1024x1024字节,可以像在Mac上一样使用tailgtail(GNU尾部)获得.

That means your image is 1024x1024 and 8 bits/sample (1 byte). Then you need to take that number of bytes from the tail end of the file and feed them into ImageMagick. So, you need the final 1024x1024 bytes which you can get with tail or gtail (GNU tail) as you are on a Mac.

gtail -c $((1024*1024*1)) EW0220149939G.IMG | convert -depth 8 -size 1024x1024 gray:- result.jpg

如果您的图片是16位的,就像在其他问题中一样,则需要使用:

If your image is 16-bit, like in your other question, you need to use:

gtail -c $((1024*1024*2)) 16-BIT-IMAGE.IMG | convert -depth 16 -size 1024x1024 gray:- result.jpg


如果您不喜欢使用gtail来获取最后一个兆字节,则可以选择从文件开头指定一个偏移量,该偏移量告诉ImageMagick像素数据从何处开始.因此,首先需要标题的大小:


If you dislike using gtail to get the last megabyte, you can alternatively specify an offset from the start of the file that tells ImageMagick where the pixel data starts. So, first you need the size of the header:

grep -E "RECORD_BYTES|LABEL_RECORDS" EW*IMG
RECORD_BYTES         = 1024
LABEL_RECORDS         = 0007

这意味着我们需要跳过1024 * 7字节才能到达图像,因此命令为:

That means we need to skip 1024*7 bytes to get to the image, so the command is:

convert -size 1024x1024+$((1024*7)) -depth 8 gray:EW0220149939G.IMG result.jpg

这篇关于ImageMagick在转换为JPG时以黑线分割NASA的[.IMG]文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆