ImageMagick is splitting the NASAs [.IMG] file by a black line upon converting to JPG

2024/11/15 23:58:00

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:

I used the command magick convert input_filename.IMG output_filename.jpg

Raw .IMG File


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

Should Look Like This


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

Actually Looking Like This


Version Details:

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
Answer

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

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

enter image description here


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

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

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
https://en.xdnf.cn/q/119600.html

Related Q&A

CV2 - rectangular detecting issue

Im trying to implement an OMR using pythons CV2. As part of the code I need to find the corners of the choices box (rectangulars) however I ran into difficulty causes by the grade sheet template. In th…

Keras/TensorFlow - high acc, bad prediction

Im new to machine learning and Im trying to train a model which detects Prague city in a sentence. It can be in many word forms.Prague, PRAHA, Z Prahy etc...So I have a train dataset which consists of …

Flask-HTTPAuth: how to pass an extra argument to a function decorated with @auth.verify_password?

Heres a small Flask app authenticated with Flask-HTTPAuth. How to pass an argument (such as authentication on/off flag, or verbosity level / debug on/off flag) to a function (such as authenticate below…

AttributeError: numpy.ndarray object has no attribute split

Given a text file with one DNA sequence on each line and joining these together I now want to split the string into 5 sequences (corresponding to each of the 5 rows). This is the file source: http://ww…

How do I determine if a lat/long point is within a polygon?

I have a shapefile of all the counties that make up my state. Using the shapefile (which contains geometric for the district polygons) I was able to use geopandas to plot the shapes in a figure. I have…

How to return different types of arrays?

The high level problem Im having in C# is to make a single copy of a data structure that describes a robot control network packet (Ethercat), and then to use that single data structure to extract data …

How do I pass an array of strings to a python script as an argument?

Ive written a swift app that outputs an array of strings. I would like to import this array into a python script for further processing into an excel file via xlsxwriter, I would like to do this as an …

Match values of different dataframes

This dataframe is the principal with the original tweets. "original_ds_.csv" id tweet --------------------------------------------- 78 "onetoone"…

EOF while parsing

def main():NUMBER_OF_DAYS = 10NUMBER_OF_HOURS = 24data = []for i in range(NUMBER_OF_DAYS):data.append([])for j in range(NUMBER_OF_HOURS):data[i].append([])data[i][j].append(0)data[i][j].append(0)for k …

Why is bool(x) where x is any integer equal to True

I expected bool(1) to equate to True using Python - it does - then I expected other integers to error when converted to bool but that doesnt seem to be the case:>>> x=23 #<-- replace with a…