Combine two pictures in one

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
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Combine two pictures in one

Post by ghostmansd »

Dear forum users, I have two images of the same size: first one is monochrome ($TEXT), and the second one is full color ($PICS). I need to perform following operations:
1. Replace all black and white pixels in $PICS to transparent.
2. Replace all white pixels in $TEXT to transparent.
3. Make a new file $OUTPUT with the same size and white background.
4. Insert to all data from $PICS and $TEXT, saving transparency.
5. Delete all files, excluding $OUTPUT.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine two pictures in one

Post by fmw42 »

can you post a link to your two images (or samples like them) and a resulting image?

What platform and version of IM are you using?

Have you read viewtopic.php?f=1&t=9620?
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Re: Combine two pictures in one

Post by ghostmansd »

I have no samples, only idea. This script will be used for combining black-white text and colored pictures. After scanning user receives two pictures: one is black-white and another one is colored with deleted text. This is the best way to make good scans for djvu documents, which is called "separated scans".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine two pictures in one

Post by fmw42 »

I am not sure I understand fully your request, but here is a try.

#Create text image:
convert -size 320x240 -background white -gravity center -font Arial -fill black caption:"THIS IS A TEXT IMAGE" text.png

#Create logo image:
convert logo: -resize 50% logo2.png

#Process to make transparent and then overlay with a white background
convert \( logo2.png -fuzz 0% -transparent white -transparent black \) \
\( text.png -fuzz 0% -transparent white \) \
-background white -flatten logo_text.png

Note I have included a -fuzz 0% which means that only perfectly black and white will become transparent. But if you change it to some non-zero value then you will make close to white or black also transparent to avoid any halo effects from antialiasing due to resizing or from creating the text.

see http://www.imagemagick.org/Usage/layers/#flatten
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Re: Combine two pictures in one

Post by ghostmansd »

fmw42 wrote:I am not sure I understand fully your request, but here is a try.
Yes, that is directly what I need.
Anthony, could you explain, please? Or provide an example.
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Re: Combine two pictures in one

Post by ghostmansd »

I think Fred's MagicWand would be perfect tool. Procedure, I think, is not very hard.

App selects white and near-white pixels with MagicWand and makes them white, excluding white and almost-white in pictures. This means that MagicWand should select only neighbor white pixels, with sensitivity about 25%. Is it possible? I've smoked MagicWand manuals, but I didn't find a way to select only neighbor pixels.

And that, of course, doesn't solve another problem: app must understand, where the text begins, and where to begin selection.
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Re: Combine two pictures in one

Post by ghostmansd »

Is anybody here? :-)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine two pictures in one

Post by fmw42 »

ghostmansd wrote:Is anybody here? :-)

What is the question? I thought your original question was resolved by my earlier response.
Post Reply