The recipe for "GIMP/Artistic Filters/Photocopy"

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
dcboo

The recipe for "GIMP/Artistic Filters/Photocopy"

Post by dcboo »

What is the "cake recipe" to get a "GIMP/Artistic Filters/Photocopy" in ImageMagick?

I developed something to get my 5 megapixel photos of documents and make them more "printable" like photocopies.

First a tried:

Code: Select all

"convert	%1 -monitor -normalize -colorspace gray -negate -blur 0x1 -edge 3 -negate -blur 0x1 -threshold 50%% %1_text.gif"
It´s an edge detection to get something closer to a photocopy. But it leaves the interior of objects void, as it detects only the edges.

After some research I got this page, that explains "-lat" with examples.
and tried

Code: Select all

"convert %1 -monitor -normalize -colorspace gray -lat 7x7-3%% %1_xerox_foto.gif"
But again I´m getting only edges.

The "GIMP/Artistic Filters/Photocopy" would be perfetc. Does anyone knows the recipe?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by fmw42 »

From their explanation:

"The Photocopy filter modifies the active layer or selection so that it looks like a black and white photocopy, as if toner transferred was based on the relative darkness of a particular region. This is achieved by darkening areas of the image which are measured to be darker than a neighborhood average, and setting other pixels to white."

I would guess something like:

convert image -colorspace gray \( -clone 0 -blur radiusxsigma \) +swap -compose minus -composite \
-threshold XX% output

or

convert image -colorspace gray -lat widthxheight-XX% output

Note the -XX% as some small negative percent is warranted.

But neither get it exactly. So further experimentation is warranted.

If someone figures it out, let us know.
Last edited by fmw42 on 2009-12-07T19:26:02-07:00, edited 1 time in total.
HugoRune
Posts: 90
Joined: 2009-03-11T02:45:12-07:00
Authentication code: 8675309

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by HugoRune »

i checked the description from gimp photocopy.c
/*
* Photocopy algorithm
* -----------------
* Mask radius = radius of pixel neighborhood for intensity comparison
* Threshold = relative intensity difference which will result in darkening
* Ramp = amount of relative intensity difference before total black
* Blur radius = mask radius / 3.0
*
* Algorithm:
* For each pixel, calculate pixel intensity value to be: avg (blur radius)
* relative diff = pixel intensity / avg (mask radius)
* If relative diff < Threshold
* intensity mult = (Ramp - MIN (Ramp, (Threshold - relative diff))) / Ramp
* pixel intensity *= intensity mult
* Else
* pixel intensity = white
*/
i don't really get what they are doing based on that though.

however, based on the picture from http://docs.gimp.org/en/plug-in-photocopy.html I would say something like:

convert taj_orig.jpg -colorspace gray -contrast-stretch 10%x0% ( +clone -blur 0x2 ) +swap -compose divide -composite test.png

Image --> Image

(adjust -contrast-stretch 10%x0% and -blur 0x2 accordingly. For larger pictures a larger blur is needed)


edit:
convert taj_orig.jpg -colorspace gray -contrast-stretch 4%x0% ( +clone -blur 0x3 ) +swap -compose divide -composite -blur 0x1 -unsharp 0x20 test.png
seems to be closer, althought I am not sure if the last blur is desirable:
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by fmw42 »

nice work! looks like you got it close. the GIMP page example is a bit blurred, so your blur at the end is likely needed.
dcboo

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by dcboo »

You got it!!!
Now I´m going to research howto clear the text to improve documents to print them black&white.

Thanks ...
See ya ..
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by fmw42 »

I don't think the first blur is needed and the unsharp can be replaced with a simpler linear-stretch on the black side. So i get pretty much the same with:


convert taj_orig.jpg -colorspace gray \( +clone -blur 0x3 \) \
+swap -compose divide -composite -blur 0x1 -linear-stretch 5x0% taj_gray_photo.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by anthony »

I like Freds results slightly better, especially with regards to the grass areas under the trees...

I have placed this in IM Examples, Photos, Color-in Outlines area.
http://www.imagemagick.org/Usage/photos/#color-in
with a note in compose divide.

give it a couple of hours to appear there!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
HugoRune
Posts: 90
Joined: 2009-03-11T02:45:12-07:00
Authentication code: 8675309

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by HugoRune »

There is however a slight problem with large almost-black areas in this case.
if such an area is larger than the blur radius, it will have white holes in it

how about
convert taj_orig.jpg -modulate 100,10 ( +clone -blur 0x3 +level 10%x100% ) +swap -compose divide -composite -blur 0x1 -linear-stretch 5x0% test.png
Image
Last edited by HugoRune on 2009-08-16T20:01:00-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by anthony »

Yes I found that out when I applied it to my 'holocaust memorial' photo (see IM Example previous link)

But I also know from experience that that is exactly what happens with a photocopier!!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by fmw42 »

how about
convert taj_orig.jpg -modulate 100,10 ( +clone -blur 0x3 +level 10%x100% ) +swap -compose divide -composite -blur 0x1 -linear-stretch 5x0% test.png
Unfortunately, your image still has some green in the grass area so is not graycale. So it needs some kind of adjustment or simply conversion to grayscale at the end.

So either:

convert taj_orig.jpg -modulate 100,0 \
\( +clone -blur 0x3 +level 10%x100% \) \
+swap -compose divide -composite -blur 0x1 -linear-stretch 5x0% test2.png

or

convert taj_orig.jpg -modulate 100,10 \
\( +clone -blur 0x3 +level 10%x100% \) \
+swap -compose divide -composite -blur 0x1 -linear-stretch 5x0% \
-colorspace gray test3.png
HugoRune
Posts: 90
Joined: 2009-03-11T02:45:12-07:00
Authentication code: 8675309

Re: The recipe for "GIMP/Artistic Filters/Photocopy"

Post by HugoRune »

Unfortunately, your image still has some green in the grass area so is not graycale. So it needs some kind of adjustment or simply conversion to grayscale at the end.
ah yes, I was experimenting how it works if I do a "color-copy" effect, i.e preserve a bit of color
For a pure grayscale image -modulate 100,0 would be right
Post Reply