merge binary files of same size

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
odul
Posts: 3
Joined: 2017-12-18T02:52:36-07:00
Authentication code: 1152

merge binary files of same size

Post by odul » 2017-12-18T03:08:12-07:00

Hi everybody,

I have pairs of fairly large binary tiff-files of same dimensions which need to be merged together.

The file data may look like that:

file1:
0000000000000000000000
0111111100000000000000
0100000100000000000000
0100000100000000000000
0100000100000000000000
0100000100000000000000
0111111100000000000000
0000000000000000000000
0000000000000000000000


file2:
0000000000000000000000
0000000000000001000010
0000000000000000100100
0000000000000000011000
0000000000000000011000
0000000000000000100100
0000000000000001000010
0000000000000000000000
0000000000000000000000


desired result:
0000000000000000000000
0111111100000001000010
0100000100000000100100
0100000100000000011000
0100000100000000011000
0100000100000000100100
0111111100000001000010
0000000000000000000000
0000000000000000000000

Any idea, how can do that? I studied the documentation, but surrendered...

snibgo
Posts: 10482
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: merge binary files of same size

Post by snibgo » 2017-12-18T03:25:18-07:00

I suppose 0 represents black, and 1 represents white? Then the output at each pixel should be the lighter of the inputs:

Code: Select all

magick in1.tiff in2.tiff -compose Lighten -composite out.tiff
snibgo's IM pages: im.snibgo.com

odul
Posts: 3
Joined: 2017-12-18T02:52:36-07:00
Authentication code: 1152

Re: merge binary files of same size

Post by odul » 2017-12-18T03:44:08-07:00

Hello snibgo,

thanks for your instant help. Unfortunately, I only get a totally white tiff as result:-(

BTW: typical file size ist 20000 times 35000 Pixels.

snibgo
Posts: 10482
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: merge binary files of same size

Post by snibgo » 2017-12-18T05:32:48-07:00

I thought that each 0 or 1 was a pixel, but perhaps not. Please tell us what they represent.

Also tell us what version of IM you are using, on what platform.
snibgo's IM pages: im.snibgo.com

odul
Posts: 3
Joined: 2017-12-18T02:52:36-07:00
Authentication code: 1152

Re: merge binary files of same size

Post by odul » 2017-12-18T14:47:09-07:00

Thanks again for your help so far. I am using

ImageMagick 6.7.6-3 2012-04-28 Q16

in a cygwin Environment running on WIN 7. My files are one color, one bit per pixel. I do not know for sure, whether "1" means full Color or "no Color". I guessed "1" means full Color and so I created the example files.

I hope, that helps:-)

snibgo
Posts: 10482
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: merge binary files of same size

Post by snibgo » 2017-12-18T15:02:33-07:00

I think it wold help if you supplied links to example inputs files. Please make them small (eg no larger than 1000x1000).
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 23595
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merge binary files of same size

Post by fmw42 » 2017-12-18T16:29:20-07:00

Binary does not support color. Binary is black and white only with 1 bit per pixel. So we do not know what you mean by color images with 1-bit per pixel. As snibgo suggested perhaps supplying your input files might help. Or explain the file format in more detail.

Perhaps you mean the images are binary as opposed to text format. But what is the bit depth per pixel per channel? Is it 8-bits per pixel per channel (as 24-bit color image)? What is the endian -- are the higher bits on the left or right of the 8bits.

Post Reply