Page 1 of 1
Cropping BMP and filesizes
Posted: 2010-06-03T16:56:01-07:00
by chuko
Hi,
I am using the CLI imagemagick convert command to crop a batch of BMP files at different geometry offsets.
The original images are BMP and have the same geometry and filesize.
When converting a pair using the following commands:
convert -crop 4008x1916+0+285 +repage -extent 4008x1916 -type palette -strip set01_0001A.bmp set01crop_0001A.bmp
convert -crop 4008x1916+0+285 +repage -extent 4008x1916 -type palette -strip set01_0001B.bmp set01crop_0001B.bmp
it creates two cropped images of different sizes which are LARGER than the original files (10710454).
set01crop_0001A.bmp - filesize: 12129946
set01crop_0001B.bmp - filesize: 11944798
Is there anyway to force them to the same filesize as each other? And make them smaller than the original?
Re: Cropping BMP and filesizes
Posted: 2010-06-03T17:23:45-07:00
by fmw42
You are not using the correct syntax for IM 6 which has the input image right after the convert, e.g.
convert input options output
That may not make a difference but try (rearranging and adding +dither -colors 256 since you are outputting an 8-bit palette format)
convert input -strip -crop 4008x1916+0+285 +repage -extent 4008x1916 +dither -colors 256 -type palette output
However consider that IM produces BMP4 by default and your input images may be BMP2 or BMP3.
For more details and limitations, see
http://www.imagemagick.org/Usage/formats/#bmp
also see
http://www.imagemagick.org/Usage/basics/#why
Re: Cropping BMP and filesizes
Posted: 2010-06-03T19:42:49-07:00
by chuko
Thanks for the quick reply.
Your advice about IM default output of BMP4 led me to test BMP2 and BMP3, the former providing a consistent filesize for a fixed geometry. However, the program I use to process this data incorrectly reads the dimensions [125570984 x 524289] when a BMP2 format is input. So, I guess I need to use BMP3 or BMP4 - however a requirement is that the filesize is consistent.
I don't understand why two BMP3 and BMP4 files of the same dimensions would have different file sizes - is it the header content?
fmw42 wrote:You are not using the correct syntax for IM 6 which has the input image right after the convert, e.g.
convert input options output
That may not make a difference but try (rearranging and adding +dither -colors 256 since you are outputting an 8-bit palette format)
convert input -strip -crop 4008x1916+0+285 +repage -extent 4008x1916 +dither -colors 256 -type palette output
However consider that IM produces BMP4 by default and your input images may be BMP2 or BMP3.
For more details and limitations, see
http://www.imagemagick.org/Usage/formats/#bmp
also see
http://www.imagemagick.org/Usage/basics/#why
Re: Cropping BMP and filesizes
Posted: 2010-06-03T19:45:57-07:00
by fmw42
without -colors 256 it is possible that BMP4 is not 8-bit but 24-bit and perhaps your input image was truly 8-bit. compare the verbose info for each image to see its bit-depth
identify -verbose image
also as you suggest, it could be the headers.
Re: Cropping BMP and filesizes
Posted: 2010-06-03T20:15:33-07:00
by chuko
Hi,
I've been using identify to try and find out more. The original image is:
Code: Select all
set01_0001A.bmp BMP 4008x2672 PseudoClass 256c 10.2mb
Image: set01_0001A.bmp
Format: BMP (Microsoft Windows bitmap image)
Geometry: 4008x2672
Class: PseudoClass
Type: Grayscale
Endianess: Undefined
Colorspace: Gray
Channel depth:
Gray: 8-bits
Channel statistics:
Gray:
Min: 0 (0)
Max: 255 (1)
Mean: 58.6435 (0.229975)
Standard deviation: 37.7538 (0.148054)
Colors: 256
Histogram:
<LOTS OF HISTOGRAM INFO>
Rendering-intent: Undefined
Units: Undefined
Filesize: 10.2mb
Interlace: None
Background Color: white
Border Color: #DFDFDF
Matte Color: grey74
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Signature: 0c239517c97f7d2eaa5e9816f9b140a53e2e708edc17aac19d100cbfe6224785
Tainted: False
Version: ImageMagick 6.2.4 02/10/07 Q16 http://www.imagemagick.org
and the cropped one is
Code: Select all
set01crop_0001A.bmp BMP 4008x1916 PseudoClass 256c 13.6mb
Image: set01crop_0001A.bmp
Format: BMP (Microsoft Windows bitmap image)
Geometry: 4008x1916
Class: PseudoClass
Type: Grayscale
Endianess: Undefined
Colorspace: Gray
Channel depth:
Gray: 8-bits
Channel statistics:
Gray:
Min: 0 (0)
Max: 255 (1)
Mean: 58.9603 (0.231217)
Standard deviation: 37.7652 (0.148099)
Colors: 256
Histogram:
<LOTS OF HISTOGRAM INFO>
Rendering-intent: Undefined
Units: Undefined
Filesize: 13.6mb
Interlace: None
Background Color: white
Border Color: #DFDFDF
Matte Color: grey74
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Signature: 8c757a13cf7979d12d1275faa6f3b423c9cf19b3d0e01130769dd33591d5e1e9
Tainted: False
Version: ImageMagick 6.2.4 02/10/07 Q16 http://www.imagemagick.org
They contain the same info, apart from filesize and geometry using
Code: Select all
convert set01_0001A.bmp -strip -crop 4008x1916+0+285 +repage -extent 4008x1916 +dither -colors 256 -type palette set01crop_0001A.bmp
and the same result if I specify BMP2, except with different filesize.
So, I suspect at the moment that I need to investigate the header and info header, and a fixed palette (if it is added to BMP).
Re: Cropping BMP and filesizes
Posted: 2010-06-03T20:23:59-07:00
by fmw42
look at the length (size) of the color palette in each image.
IM 6.2.4 is rather old. You may find that upgrading fixes lots of problems and perhaps this. You are about 380 versions old.
Re: Cropping BMP and filesizes
Posted: 2010-06-03T20:29:00-07:00
by fmw42
Code: Select all
convert set01_0001A.bmp -strip -crop 4008x1916+0+285 +repage -extent 4008x1916 +dither -colors 256 -type palette set01crop_0001A.bmp
-extent 4008x1916 is superfluous since your have already cropped your image to 4008x1916.
Try removing it and see what happens to the file size.
Re: Cropping BMP and filesizes
Posted: 2010-06-03T20:34:07-07:00
by fmw42
see
http://en.wikipedia.org/wiki/BMP_file_format (regarding headers and compression)
perhaps your input image was compressed (even though IM verbose info did not recognize it) and your output is not compressed.
Re: Cropping BMP and filesizes
Posted: 2010-06-04T03:33:39-07:00
by Drarakel
Probably it's the other way round - you have uncompressed input files, but the output files are compressed. This doesn't get displayed in the verbose output (I'm using current IM versions though). I think, the default for ImageMagick when it has to write 8bit BMPs is to use a BMP V3 header and RLE compression (which can be inefficient).
You either have to write as 'BMP2:' (which creates a uncompressed file with BMP V1 header), or specify '-compress none'.
So, use something like this:
Code: Select all
convert set01_0001A.bmp -crop 4008x1916+0+285 +repage -compress none set01crop_0001A.bmp
Re: Cropping BMP and filesizes
Posted: 2010-06-07T01:31:03-07:00
by chuko
Hi all,
thank you for all your advice - this worked. However, what is interesting is that the file size was smaller when -compress none was included. In fact it was the size of the 8bit x geometry + a little bit extra. Without it, it was double the size. The BMP2 worked to keep the size the same, but excluded some header info that the program I fed it to must have required.
Drarakel wrote:Probably it's the other way round - you have uncompressed input files, but the output files are compressed. This doesn't get displayed in the verbose output (I'm using current IM versions though). I think, the default for ImageMagick when it has to write 8bit BMPs is to use a BMP V3 header and RLE compression (which can be inefficient).
You either have to write as 'BMP2:' (which creates a uncompressed file with BMP V1 header), or specify '-compress none'.
So, use something like this:
Code: Select all
convert set01_0001A.bmp -crop 4008x1916+0+285 +repage -compress none set01crop_0001A.bmp