photo effect - Warholize - line art

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?".

photo effect - Warholize - line art

Postby myspacee » 2009-01-01T18:04:00+00:00

hello,
sorry for biazzarre post, but is only for fun
(apologize, is 1st day of year...)

Find nice imagemagick use :
Warholize http://www.vincent-richard.net/blog/index.php/2007/05/24/6-effet-andy-warhol
but script is for linux only, is possible to have counterpart for windows ?

and an effect that i ask only if is replicable with IM, line art as found:
http://fotofamilymemories.com/category/phototechnique/

thank you for your attention,

m.
myspacee
 
Posts: 116
Joined: 2007-06-14T02:09:35+00:00

Re: photo effect - Warholize - line art

Postby anthony » 2009-01-02T03:52:32+00:00

The technique from what I can see uses GIMP which is available both in linux and in windows!

It is not automatic, and requires input from the user to get right for each photo involved.

IM can do the steps specified but the steps will be slightly different for each photo involved.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8732
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: photo effect - Warholize - line art

Postby rmabry » 2009-01-02T08:45:53+00:00

anthony wrote:IM can do the steps specified but the steps will be slightly different for each photo involved.


Cute effect. Here's one with many cat photos.

http://www.urban-warrior.org/mosaicks/m ... osaick.jpg

Rick
rmabry
 
Posts: 132
Joined: 2004-04-13T11:25:27+00:00

Re: photo effect - Warholize - line art

Postby myspacee » 2009-01-08T04:39:13+00:00

find linux bash script :

Code: Select all
#!/bin/bash
#
# 'Andy Warhol'-like effect using ImageMagick
#
# Copyright (c) Vincent RICHARD, 2007
# vincent@vincent-richard.net
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#

###################
#  CONFIGURATION  #
###################

# Quality for output image (if compressed)
QUALITY="90%"

# Define colors to be used in output image
# -- top-left quadrant
C1_B="#342b7c"
C1_G="#94c015"
C1_W="#fefc09"
# -- top-right quadrant
C2_B="#ee6807"
C2_G="#9ec038"
C2_W="#fff9a3"
# -- bottom-left quadrant
C3_B="#734995"
C3_G="#79bef9"
C3_W="#f58508"
# -- bottom-right quadrant
C4_B="#e60877"
C4_G="#fdf107"
C4_W="#0483ee"


############
#  SCRIPT  #
############

# Check arguments
if [ $# -ne 2 ]; then
   echo "Usage: $0 input-file output-file"
   exit 1
fi

# Reduce the number of colors to 3 (black, white and a level of gray).
# Store the output in a temporary file.
TEMP_FILE=`tempfile --suffix=.png`

convert "$1" -background white -flatten +matte -colorspace gray -colors 3 -colorspace rgb -type TrueColor -matte "$TEMP_FILE" \
   || ( echo "$0: could not reduce colors in input image" ; exit 2 )

convert "$TEMP_FILE" -channel ALL -normalize "$TEMP_FILE" \
   || ( echo "$0: could not normalize input image" ; rm -f "$TEMP_FILE" ; exit 3 )

# Extract histogram (list of colors) from the image.
# We are only interested in the gray color, so remove black and white lines.
HISTO=`convert "$TEMP_FILE" histogram:- | identify -format %c - | grep -vre "black\|white"`

# Ensure we got only one line
HISTO_LINES=`echo "$HISTO" | wc -l`

if [ $HISTO_LINES -eq 0 ]; then
   echo "$0: could not get histogram"
   rm -f "$TEMP_FILE"
   exit 4
fi

if [ $HISTO_LINES -ne 1 ]; then
   echo "$0: cannot extract colors from histogram"
   rm -f "$TEMP_FILE"
   exit 5
fi

# Extract the color from a line in the form:
#     105037: (119,119,119, 0) #77777700
# or: 32765: (163,163,163, 0) grey64
GRAY=`echo $HISTO | expand | sed 's/ /\n/g' | grep -E -m 1 "^(#[0-9a-zA-Z]{3,12}|[a-zA-Z][a-zA-Z0-9]+)$" | tr -d " \t"`

if [ -z "$GRAY" ]; then
   echo "$0: cannot extract gray color value"
   rm -f "$TEMP_FILE"
   exit 6
fi

# We can now set colors to replace
BLACK="#000000000000"
WHITE="#FFFFFFFFFFFF"
GRAY="$GRAY"

# Apply filter.
#
# * Step 1: apply median filter to get ride on small details
#
# * Step 2: repeat 4 times:
#  - clone the 3-color image ("TEMP_FILE")
#  - replace black, gray and white with their corresponding values Ci_B, Ci_G, Ci_W;
#    to do this we use "-fill TO_COLOR -opaque FROM_COLOR" command
#  - stack the resulting image after the previous one (2 columns, 2 rows)
#
# * Step 3: apply spread filter to "soften" edges

convert "$TEMP_FILE" -median 2 -fuzz 0% \( -clone 0 \( -clone 0 -fill "$C1_W" -opaque "$WHITE" -fill "$C1_G" -opaque "$GRAY" -fill "$C1_B" -opaque "$BLACK" \) \( -clone 0 -fill "$C2_W" -opaque "$WHITE" -fill "$C2_G" -opaque "$GRAY" -fill "$C2_B" -opaque "$BLACK" \) -delete 0 +append \) \( -clone 0 \( -clone 0 -fill "$C4_W" -opaque "$WHITE" -fill "$C4_G" -opaque "$GRAY" -fill "$C4_B" -opaque "$BLACK" \) +append \( -clone 0 -fill "$C3_W" -opaque "$WHITE" -fill "$C3_G" -opaque "$GRAY" -fill "$C3_B" -opaque "$BLACK" \) -delete 0 \) -delete 0 -append -spread 1 -quality $QUALITY "$2" \
   || ( echo "$0: could not apply filter" ; rm -f "$TEMP_FILE" ; exit 7 )

# Delete temporary file
rm -f "$TEMP_FILE"

# Success
exit 0


but have some problem to 'convert' script for windows:
(replace all variables with value)

Code: Select all
convert DSCFinput.JPG -background white -flatten +matte -colorspace gray -colors 3 -colorspace rgb -type TrueColor -matte DSCF999.JPG

convert DSCF999.JPG  -channel ALL -normalize DSCF999.JPG

convert DSCF999.JPG histogram:- | identify -format %c

convert DSCF999.JPG  -median 2 -fuzz 0%% \( -clone 0 \( -clone 0 -fill #fefc09 -opaque #FFFFFFFFFFFF -fill #94c015 -opaque #F0F0F0F0F0F0 -fill #342b7c -opaque #000000000000 \) \( -clone 0 -fill #fff9a3 -opaque #FFFFFFFFFFFF -fill #9ec038 -opaque #F0F0F0F0F0F0 -fill #ee6807 -opaque #000000000000 \) -delete 0 +append \) \( -clone 0 \( -clone 0 -fill #0483ee -opaque #FFFFFFFFFFFF -fill #fdf107 -opaque #F0F0F0F0F0F0 -fill #e60877 -opaque #000000000000 \) +append \( -clone 0 -fill #f58508 -opaque #FFFFFFFFFFFF -fill #79bef9 -opaque #F0F0F0F0F0F0 -fill #734995 -opaque #000000000000 \) -delete 0 \) -delete 0 -append -spread 1 -quality 90%% FINAL.JPG \


for first thing don't understand and replace code for :

Code: Select all
convert DSCF999.JPG histogram:- | identify -format %c


anyone can help me ?

m.
myspacee
 
Posts: 116
Joined: 2007-06-14T02:09:35+00:00

Re: photo effect - Warholize - line art

Postby anthony » 2009-01-08T20:02:21+00:00

myspacee wrote:for first thing don't understand and replace code for :

Code: Select all
convert DSCF999.JPG histogram:- | identify -format %c



It extracts the JPEG images 'comment'. probably storing it in some variable so it can later draw/annotate it onto the resulting image.

See percent escapes
http://imagemagick.org/script/escape.php
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8732
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: photo effect - Warholize - line art

Postby myspacee » 2009-01-10T07:26:47+00:00

thank you for reply, now reading...

anyone can help to adjust linux script to obtain working example for windows geeks ?

thank you,

m.
myspacee
 
Posts: 116
Joined: 2007-06-14T02:09:35+00:00

Re: photo effect - Warholize - line art

Postby rmabry » 2009-01-10T11:15:45+00:00

myspacee wrote:anyone can help to adjust linux script to obtain working example for windows geeks ?


This part is the main problem, as you noted:

Code: Select all
HISTO=`convert "$TEMP_FILE" histogram:- | identify -format %c - | grep -vre "black\|white"`


As far as I know, Windows cannot do anything remotely like it. The back-quotes, for instance, are just a fantasy for Windows programmers, I believe. And then redirection of an image via standard input and output --- Windows would choke on it. (Someobody correct me if I am wrong!)

But a batch file is doable, I'l bet, with loads of work. I suspect you need to write the histogram to a separate file and then use identify on that if you want to replicate the rest of your process.

But I also suspect that there is a much easier way to achieve a similar effect without resorting to the histogram. Something along these lines:

Code: Select all
convert ( warhol-in.jpg -colorspace gray -colors 3 ) ( -size 3x1 xc:white -fill red -draw "color 0,0 point" -fill green -draw "color 1,0 point" -fill blue -draw "color 2,0 point" ) -interpolate integer -clut  cat.gif


Most of that is just to get the three colors into a 3-pixel file that can them be used for color replacement using -clut, and there is surely a more elegant way to create a 3-pixel file.

Rick
rmabry
 
Posts: 132
Joined: 2004-04-13T11:25:27+00:00

Re: photo effect - Warholize - line art

Postby anthony » 2009-01-11T17:07:40+00:00

rmabry wrote:Most of that is just to get the three colors into a 3-pixel file that can them be used for color replacement using -clut, and there is surely a more elegant way to create a 3-pixel file.

Right you are -unique-colors

This just creates a image 1 pixel high, and N pixels long where N is the number of colors in the image.
Extracting Image Colors
http://www.imagemagick.org/Usage/quantize/#extract

However the order of the colors are undefined as it depends on the oct-tree representation of the color space used by Colro Quantization. Basically the color reduction data handling.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8732
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: photo effect - Warholize - line art

Postby rmabry » 2009-01-11T19:07:21+00:00

anthony wrote:Right you are -unique-colors


But here we want to choose the colors. What's the nicest way to get a 3x1 image cosisting of purple, then white, then #2277ff?
rmabry
 
Posts: 132
Joined: 2004-04-13T11:25:27+00:00

Re: photo effect - Warholize - line art

Postby anthony » 2009-01-11T20:12:17+00:00

What's the nicest way to get a 3x1 image cosisting of purple, then white, then #2277ff?
Code: Select all
 convert  xc:purple  xc:white  xc:'#2277ff' -append  3_colors.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8732
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: photo effect - Warholize - line art

Postby rmabry » 2009-01-11T20:55:52+00:00

Ha! Super slick. So -size defaults to 1x1, not bad. The earlier command is now much faster:

Code: Select all
convert ( warhol-in.jpg -colorspace gray -colors 3 ) ( xc:purple xc:"#123456" xc:yellow  -append ) -interpolate bicubic -clut  cat.gif


That's for Windows only, of course --- no escapes of parentheses. No quotes on the # needed in Windows, either, but it doesn't hurt.

Thanks, Anthony.
rmabry
 
Posts: 132
Joined: 2004-04-13T11:25:27+00:00

Re: photo effect - Warholize - line art

Postby anthony » 2009-01-11T21:26:29+00:00

You can also use ^ to continue onto the next line to make it look neater and seperate actions by lines
Code: Select all
convert ( warhol-in.jpg -colorspace gray -colors 3 ) ^
        ( xc:purple xc:"#123456" xc:yellow  -append ) ^
        -interpolate bicubic -clut  cat.gif


PS: the first set of parenthesis is not needed as there are no image in memory yet, but it don't hurt either :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8732
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: photo effect - Warholize - line art

Postby Tagomago » 2011-02-16T10:57:09+00:00

The comments so far on this warhol script have asked how to convert it to windows... anyone have an idea why these problems came up in Cygwin for windows?

T3500 ~
$ ./warhol test400.jpg warhol.jpg
./warhol: line 18: $'\r': command not found
./warhol: line 22: $'\r': command not found
./warhol: line 25: $'\r': command not found
./warhol: line 43: $'\r': command not found
./warhol: line 44: $'\r': command not found
./warhol: line 48: $'\r': command not found
./warhol: line 60: syntax error near unexpected token `||'
./warhol: line 60: ` || ( echo "$0: could not reduce colors in input image" ;
'xit 2 )
Tagomago
 
Posts: 36
Joined: 2011-02-10T09:55:33+00:00

Re: photo effect - Warholize - line art

Postby Tagomago » 2011-02-18T07:57:51+00:00

Below is the rough version of how I got a Warhol style image.

Question, though: could anyone point me to a guide on combining this many commands in windows command prompt? Or, put another way, is it possible to create and manipulate four seperate images within the same command? I'm hoping to do batch processing with this.

convert test.jpg -resize 400 hue1.jpg
convert test.jpg -resize 400 hue2.jpg
convert test.jpg -resize 400 hue3.jpg
convert test.jpg -resize 400 hue4.jpg

convert -modulate 100%,100%,15% hue1.jpg hue1.jpg
convert -modulate 100%,100%,55% hue2.jpg hue2.jpg
convert -modulate 100%,100%,95% hue3.jpg hue3.jpg
convert -modulate 100%,100%,145% hue4.jpg hue4.jpg

convert -size 800x600 xc:white warholize.jpg

composite -gravity NorthEast hue1.jpg warholize.jpg warholize.jpg
composite -gravity NorthWest hue2.jpg warholize.jpg warholize.jpg
composite -gravity SouthEast hue3.jpg warholize.jpg warholize.jpg
composite -gravity SouthWest hue4.jpg warholize.jpg warholize.jpg
Tagomago
 
Posts: 36
Joined: 2011-02-10T09:55:33+00:00

Re: photo effect - Warholize - line art

Postby fmw42 » 2011-02-18T11:03:17+00:00

Here is one way using the cat image and my tricolorize script:

Image

convert cat1.jpg -colorspace gray catgray.jpg
tricolorize -l yellow -m blue -h red catgray.png cat1gray_tri1.jpg
tricolorize -l green -m magenta -h violet catgray.png cat1gray_tri2.jpg
tricolorize -l blue -m green -h orange catgray.png cat1gray_tri3.jpg
tricolorize -l magenta -m yellow -h cyan catgray.png cat1gray_tri4.jpg
montage cat1gray_tri1.jpg cat1gray_tri2.jpg cat1gray_tri3.jpg cat1gray_tri4.jpg \
-tile 2x2 -geometry +5+5 -background white \
catgray_warhol.jpg

Image
User avatar
fmw42
 
Posts: 15028
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Next

Return to Users

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests