Page 1 of 1

Clone stamp tool for ImageMagick?

Posted: 2010-09-15T14:10:57-07:00
by gillespie
Hi guys. Just wondering if there's a clone stamp tool (like Photoshop) for ImageMagick? Can IM do that?

Thanks!

Re: Clone stamp tool for ImageMagick?

Posted: 2010-09-15T14:31:58-07:00
by fmw42
Not directly. You have to crop and mask the area you want to clone, then composite it in various locations on the background image using something like -page ... -flatten.

see
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/layers/

Note IM is command line driven, so you don't have the Gui base that is in Photoshop and other tools.

Re: Clone stamp tool for ImageMagick?

Posted: 2010-09-16T18:18:39-07:00
by lwhistler
I'm working on a "clone" bash script to removal dust spots from multiple images. The dust spot would be replaced with the pixels next to it. Below is an example of it in action, but on a bigger scale than dust spots.

image.jpg
Image
Original image - In this example I will clone the red car, and copy it to the left.

mask.png
Image
In GIMP create a mask.png file to mask out entire image, except for cloned area. The black area is in the same position as red car.

clone.sh

Code: Select all

#!/bin/bash
COUNTER=1

for image_file in *.jpg
do
counter=`printf %06d $COUNTER`
convert $image_file \( mask.png -negate \) -alpha off -compose CopyOpacity -composite \
\( +clone -channel RGBA +channel  -alpha off \) +swap -compose Over -geometry -75+0 -composite output_$counter.jpg
let COUNTER=COUNTER+1
done
Save as an executable .sh file and place in same folder as jpg images. Click to execute.
The -geometry -75+0 part is what moves the cloned area to desired location.
The above code is a work in progress and I will be making changes to it.


output_000001.jpg
Image
Output image



Len Whistler

Re: Clone stamp tool for ImageMagick?

Posted: 2010-09-25T15:29:50-07:00
by Calvin
Hi Len,

I have searched high-and-low for a simple, automated way to do batch dust removal. My only other option was to use Nikon Capture NX but you cannot run that from the commandline.

Do you have any tips for taking dust reference photos? I have taken several dust ref photos the way that Nikon suggests for their dust removal system:

1) Set to Aperture-Priority
2) Manual focus to infinity
3) Zoom lens to longest focal length on a white surface, filling the frame (i tried a white sheet of paper and my lcd screen filled with white)
4) Shoot at lowest aperture possible (highest F number)

Each time I try I get what looks like light fall-off around the edges. This is not apparent from the file directly off the camera (which is mostly a very muted gray) but when I increase the contrast to bring out the dust spots.

One other thing, can you show me how you might reverse the clone source and target in your script? Because if the black spot on the dust ref file represents the dust, your published script is actually cloning the dust somewhere else on the image and rather than removing it, you end up with two dust spots!

Thanks,

Calvin

Re: Clone stamp tool for ImageMagick?

Posted: 2010-09-25T18:58:17-07:00
by lwhistler
Calvin wrote:Do you have any tips for taking dust reference photos? I have taken several dust ref photos the way that Nikon suggests for their dust removal system:

1) Set to Aperture-Priority
2) Manual focus to infinity
3) Zoom lens to longest focal length on a white surface, filling the frame (i tried a white sheet of paper and my lcd screen filled with white)
4) Shoot at lowest aperture possible (highest F number)
I don't take any "dust reference photos" at all because shots taken at f22 will have a lot more dust spots than shots taken at f5.6. I prefer to shoot at f5.6 or f8 and usually don't get any dust spots, but sometimes a higher aperture is unavoidable.

So I will study the actual shots for dust, and in GIMP create a mask over the image.
Calvin wrote:One other thing, can you show me how you might reverse the clone source and target in your script? Because if the black spot on the dust ref file represents the dust, your published script is actually cloning the dust somewhere else on the image and rather than removing it, you end up with two dust spots!
The black spot on the dust ref file can also represent the area you would like cloned into the dust spot, so you mask out the area next to the dust spot.