If you'd like to upload plug-ins, please create an account below. Otherwise (e.g. for download or commenting) you do not need one! Enjoy :-)
I work at a firm that uses large images for all kinds of things, especially with AutoCad.
Took me years to find GIMP, as there are so many free image prog's, but most do not handle large images. Happy I found it.
Here are my main tasks that I would like help on with GIMP:
1) convert a color image to black and white - in a special way. In Corel PP, there is a tool that lets you adjust a threshold slider to determine what pixels go to black and white. It also uses a "lineart" filter that seems to do well with ignoring noise (scattered pixels) at the same time. I am looking for a similar tool that allows control of what goes to black and white.
2) merge an image into another, by pasting the image in, then scaling, rotating, translating to line up with say two points in common. I can do it in several steps, but it would be nice to specify a pt1 from, and pt1 to, then pt2 from and pt2 to. It would handle the three transformations for me and line up the image.
So anything available would be great, or letting me know what API is best for these level tasks would be helpful. I do C# so can dig into that or use the scripting mechanism I noticed.
thanks
Here is the script:
Hi jmaeding!
Saw this conversation 2 days ago and needed exactly the same functionality in GIMP.
So I did the hack in 2 days. Hope this helps.
I have never heard of SCHEME or LISP before. So this was a great pile of sh.t for me.
But finally I succeeded.
I called the script "Exact Aligner" - because I'm an orthodontist and need to make model cast setups for building clear aligners where I have to control by picture the amount of tooth movement. Therefore I needed this feature in GIMP.
How to use - in short:
You load 2 pictures in separate images, copy one and paste it into a new layer of the other image, close the first picture, define transparency of second layer and stroke a path with 4 points in a row (covering 2 points on each picture for alignment) and start the script. That's it.
So here it is. Enjoy!
If anybody needs the script in original, just drop a note to my email box.
Cheers
Volker Tries
------------>8 ------------- snip ---------------- 8< ------------------------------
; Exact Aligner - (c) 2009 Dr. Volker Tries
; volker.tries@kfopraxis-oberursel.de
;
; v. 0.1_alpha 2009/10/01
;
;
; This is the Exact Aligner TinySCHEME script for GIMP
; for overlaying two pictures by clicking on the same
; 2 points in each picture.
;
; How to use this tool:
;
; -1) Copy the script into the script folder of Gimp
; In my installation it is in
; D:\Programme\GIMP-2.0\share\gimp\2.0\scripts
; 0) Now start GIMP (you have to start GIMP AFTER you copied the script!
; 1) Open 2 pictures.
; 2) In one picture do "select all" (CTRL-a) and copy (CTRL-c).
; 3) Click on the other picture an paste the copied picture
; as a new layer (CTRL-v) into it.
; 4) Close the first picture. We don't need it any more. Otherwise it only will disturb our script.
; 5) Set transparency of the layer to 50% (slide bar in the upper part
; of the layer manager). If you don't see the layer manager, just press CTRL-l.
; 6) Select the path tool in the tool box.
; 7) Now first click 2 points in the first picture (background layer)
; and then the same two points in the second picture (second layer)
; 8) We are almost done! Now choos the script from the menu bar
; unser "Tries Tools -> Exact Aligner". That's it.
;
;
;
; If you encounter error messages, you
; - probably didn't close the first picture or
; - haven't choosen the 4 reference points
; before calling the script.
;
; ***** IMPORTANT *******
;
; This script is supposed to be very buggy!
; two days ago I didn't know about this TinyScheme stuff and today the
; script works fine for me.
; If you have any recommendations or even bug reports, please contact me
; under my email address shown above.
; In the meantime enjoy this script!
;
; * * * * * * * * * * * * * * * * * * * * * * * *
;
; 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.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
(define
(script-fu-exact-overlay )
; this is the code...
(let* (
; define our local variables. We need the "*" after let to have TinySCHEME
; declare the variables exactly this order.
; here is the first images object in the program...
(theImageID1 (aref (cadr (gimp-image-list)) 0))
;here is the first vectors object from the first images object...
(theVectorID1 (car (gimp-image-get-active-vectors theImageID1)))
;here is the first strokes object in the first vectors object...
(theStrokeID1 (aref (cadr (gimp-vectors-get-strokes theVectorID1)) 0))
; First lets find out the points of the polygon you just created with the path tool in GIMP.
; The first 2 points (first pair) are the reference points in picture of layer1 ,
; the second pair are the same points, but now in picture of layer2
;define point1...
(theP1_x (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 0))
(theP1_y (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 1))
;define point2...
(theP2_x (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 6))
(theP2_y (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 7))
;define point3...
(theP3_x (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 12))
(theP3_y (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 13))
;define point4...
(theP4_x (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 18))
(theP4_y (aref (caddr (gimp-vectors-stroke-get-points theVectorID1 theStrokeID1 )) 19))
; Now let's do some simple math to get
; - rotation angle (camera was rotated between two shots)
; - displacement (for translation or offset. e.g., by pointing the camera to a different center of image)
; - rescaling (in case the the viewing angle
; has changed from picture 1 to picture 2., e.g., by choosing another focal leth or chaning the distance to the photographic object)
; Dx1, Dx2, Dy1, Dy2...
(theDx1 (- theP2_x theP1_x))
(theDy1 (- theP2_y theP1_y))
(theDx2 (- theP4_x theP3_x))
(theDy2 (- theP4_y theP3_y))
; the angle between the two lines. i.e., the angle layer2 must be clockwise rotatet
; in order to overlap with layer1...
(theAngle (- (atan (/ theDy1 theDx1) ) (atan (/ theDy2 theDx2))))
;the scale factors layer2 must be mulitplied by in order to fit onto layer1
; this is simply the ratio of the two line lenths from the path we created with the 4 points
; For distinct x and y scale factors we need to have another point.
; But I don't need this so I didn't implement it yet.
(theScaleX (/ (sqrt (+ (* theDx1 theDx1) (* theDy1 theDy1))) (sqrt (+ (* theDx2 theDx2) (* theDy2 theDy2))) ) )
(theScaleY (/ theDy1 theDy2)) ; we need more then 2 points to calculate seperate scale factors for x and y axis if we also want de-rotation!!!
(set! theScaleY (theScaleX)) ; this is for convenience and future use!!
; the last info we need is the active drawable of the image
(theActiveDrawableID (car (gimp-image-get-active-drawable theImageID1)))
) ; end of variable definition --------------------------------
; now we can make the transformation:
(gimp-context-push)
; --------- TRANSFORMATION ----------------------
; we do the transformation in one function call......
(gimp-drawable-transform-2d theActiveDrawableID theP3_x theP3_y theScaleX theScaleX theAngle theP1_x theP1_y 0 0 TRUE 1 1)
(gimp-displays-flush)
(gimp-context-pop)
) ; end of local declaration
)
;Now we want to register this stuff...
(script-fu-register "script-fu-exact-overlay"
_"/Tries-Tools/Exact Aligner"
"Exact projection of 2 images in 2 layers"
"Dr. Volker Tries"
"(c) 2009, Dr. Volker Tries - Volker.Tries@kfopraxis-oberursel.de"
"Sep 30, 2009"
""
)
Script is now uploaded
Thanx, Chris, for your helpful hints and remarks!!!
The script is now uploaded into the database.
http://registry.gimp.org/files/exact-aligner.scm
The trouble with the script registration in GIMP was, that the image tag in the menu registration path
_"<Image>/Tries-Tools/Exact Aligner"
__^^^^^^^
vanished by publishing it here in the forum.
The database file should work fine now.
Thanx again for your help, Chris!
Cheers
Volker
Nice - but next time upload
Nice - but next time upload the script to the registry : on the left of the page, go to Create Content->Script and attach the file there. Others will be able to find it easily using this method.
One thing: I did not see it in the menu until I changed the register params:
(script-fu-register "script-fu-exact-overlay"
_"/Tools/Tries-Tools/Exact Aligner"
Good work though! I did a little testing and it seems to work pretty well.
Chris
Changing Params Didn't Work For Me
I did the same thing, Chris, it's not showing up in my menu at all. I'll try again with a fresh clean script.
*A fresh clean script did the trick for the menu*
But now I am getting this error:
Execution error for 'Exact Aligner':
Error: vector-ref: out of bounds: 12 *
Reading the instructions on the script says to click the same two points on both images, then run the script. I tried this two ways: 1) I created two separate paths, one for each image, and 2) created one path with 4 points (2 clicks each layer). The above error resulted both ways.
The reason for this error is that my second set of points fell on the first two sets and GIMP didn't recognize the second set of points. To resolve this, I clicked the second set of points outside the first two, and manually moved them to their proper locations, then ran the script and it worked fine.
If pictures are pretty idential already...
try moving/displacing one image even more from the other image.
Than stroke your path with the 4 points. It will be easier to find the exact points in the pictures.
You also can magnify the area where the 4 points are contained. Then stroke the path with even more acuracy.
Cheers
Volker
I tried that, and it works better, thanks
Good idea, just relocating the image keeps the paths from being so close together. Works a lot better when you re-align the images, as you suggested.
My menu issue was a Vista 64 bit issue, I have to run everything (even notepad) as administrator before changes I make to any script will take place. I forgot to mention that earlier.
Thank you for the script, Dr. Tries! :)
Great stuff guys! I need to
Great stuff guys!
I need to read up on this language because it seems to be a lisp variant.
I do tons of lisp for autocad, so just need to understand the "object model" of GIMP. I've got a list of items I'd like to write so I'll post back as I get to them.
Thanks for the script!
1. 'Colors - Threshold' menu
1. 'Colors - Threshold' menu item
holy histograms batman!
wow, right in front of me. I had not loked at that because I did not expect it to convert to black and white, just keep as color.
This is a really nice feature, as it even shows the color distribution in the 'gram. Thesae new programs offer too many good things at once, takes a while to sort through them :)
Just A Question
Are the images you speak of in #2 - photographs of land, like aerial images? Or pictures of drawings, like tiff files, etc? Because in order for this to be an effective script for this sort of merge it would require the images be at identical scale. Just curious.
well, the images could be
well, the images could be from anywhere. Sometimes I start with an aerial photo, then want to paste in contour linework from a USGS topo map. I would want to bring in the usgs topo as a layer, then rotate and scale that so two points on the topo line up with two points on the aerial photo.
got trig?
I actually noodled around w/this the other day but did not get anywhere. I though that maybe if you drew two paths (from pointAlayer1->pointAlayer2, and pBl1->pBl2), you could deduce the amount of rotation and scale needed.
BUT, it's been so long since I've taken trig that I even had to look up the Pythagorean theorem to double-check. (Ouch.) If someone is willing to throw out some basic equations for the transforms above, I'd give it another shot...
Have you checked out GRASS?
You never mentioned using any other software, just thought I would mention this in case you haven't heard of it. You might want to give it a look.
http://grass.osgeo.org/
well, I have AutoCad, Corel
well, I have AutoCad, Corel Photo-paint, and a few others.
AutoCad can line up and "merge" images, but it has no transparency feature.
I might want to ovelay a USGS on an Aerial photo and be able to see some of both.
Autocad only lets you "drape" one image on surfaces it makes, so you must do the image merge outside acad.
Typically, the two images are not the same size (in pixels) or rotation, so you need a fast way to line up in image prog that does allow transparency and can handle the rather large images (8kx8k pixels many times).
CAD and TIFs with GIMP
Hi,
I work as a draftsman for a civil firm and may have a little "quick fix" for your problem.
We have to work with USGS maps too (The old ones that index at every 50' and 10' intervals) and I have found a way to make them transparent in autocad.
Here are the steps:
1)Open the topo in Gimp
2) crop the topo to the section you need
3) Create a new GIMP file that is the size of your cropped file and make sure you set the background to Transparent (under advanced options)
4)go back to the USGS and use the "Select By Color Tool" to highlight any undesired items (such as the green vegetation blotches) and delete them out.
5) Use "Select By Color Tool" again when you have cleared out all the stuff you didn't want and select some point in the white space again.
6) Invert your selection and copy it to the transparent file you made.
7) Save the new file as a TIF (Compression= None and Save color values from transparent pixels is checked)
8) Insert your new picture into AutoCAD
9) Select the image
10) In the Properties Box you can change Transparency to Yes
11) Now you can right click and set draw order and "Bring to Front"
12) Bring in your aerial image and slide it under.
It's not exactly what you wanted, but it works for us when we need to do rough layouts and cost estimates for grading.
(It also works alright with FEMA FIRMet maps (If you pull it from their website it's already saved as a TIF and you just have to set the transparency)
I hope it helps you out until you get the merge script going.
Transformation to get 2 images in exact overlap
Did you find a solution for your 2. issue? The transformation?
I'm seeking since Month for a easy solution. No success...
I can do all the math, but don't know how to implement it into the gimp interface: i.e. I don't know how to hand over cooridantes of the vectors in both images to get in exact overlaping into script-fu functions. Once I know that, i can create a new image with two layers and do all the transformation needed.
no solution yet to lining up
no solution yet to lining up images.
I can do the math also, but have never programmed a script-fu function.
Are you saying you know script-fu, but not how to tell gimp to rotate and translate the images?
thx
Missunderstanding:
I know how to write the script and transforming the image but don't know how to get the 2 vectors (2 points on each image forms a vector on each image for translation, scaling and rotating, as you know) from the GUI to the script.
Heard that using polygones (called vectors in Script-Fu) might help. I'm experimenting...
getting vector from image, image alignment on vectors script
gimp_image_get_vectors ()
will get a list of vectors from an image.
See the gimpimage section of:
http://developer.gimp.org/api/2.0/libgimp/index.html
which documents the gimp procedures that can be called from scripts.
I suppose that one would draw a vector in each image, then call a plugin to align the two images into a new image (or layer) with the vectors aligned.
A rough outline of the script
# Assume only two images are open
gimp_image_list ()
for each image:
# assume each image has only one vector
gimp_image_get_vectors ()
# do the math on the two vectors, get a transformation matrix
# or translate, scale, rotate parameters
# create new image in a duplicate
gimp_image_duplicate # the first image
gimp_image_select_all # from the second image
gimp_edit_copy
gimp_edit_paste # into the duplicate
# probably more needed here to anchor a floating selection
# more needed here to activate image and get the active layer (which is a drawable)
# transform one of the image copies
gimp_drawable_transform_matrix
The devil is in the details, I'm sure there are tedious details I am glossing over. I'm agreeing with you all, its very doable (and must have been done before.) I am saying that the functions all seem to be in the PDB (the library).
If I was doing it, I would do it in Python.
If this is a group/collaborative/cooperative programming effort, maybe there is a better forum?
plashless, off banks of noon
Good Idea so far
Thanx so much for your help!!!
I tried it already today.
But the big problem is that I cannot create two paths (= vectors) in two different images which happily coexist.
As soon as I tried to klick into the second image in order to start a new vector (path), the vector in the first image disapeares immediately.
I realized it just before finishing the script. I was so proud - and then so disappointed.
What a pitty!! GIMP sometimes is a nightmare!!!!
I'm on for another solution now: reading the 2 bitmaps into different layers of the same image.
Than using the path tool again, do all the math and transformation (which can be easily done by gimp-drawable-transform-2D...).
Maybe you have another easy solution for this!
Thanx
Peta
Don't know if this helps,
Don't know if this helps, but I've pasted what I was playing around with (in the Python-Fu console):
http://pastebin.com/f4e068a4
I also thought that you need to use two layers. My thoughts were that if you make the top layer somewhat transparent, then draw two paths - from point A to point A and then point B to point B, then you would have enough information to do a precise rotate+scale.
But as you can see, I started messing up the math a bit :)
Chris
Thats exactly the point!
I'm exactly working on this solution and am almost finished.
I'm still trying to make it more dummy user friendly by simply selecting 2 pictures, let the user define the 4-point polygon and finaly finishing with the transformation.
Chris: Thanx so long for having the same thoughts!
2 days ago I just learnd this Script-Fu stuff (ugh :-((
I'm trying to avoid learning another scripting language from scratch again. Need a quick solution.
But Python looks a little more human to me. Maybe I should give it a try...