Episode 129: Octave Sharpening Python Plugin

129Download the Video! (77.0 MB, 40:31)
Download the Companion File!

This is the second time I try to get into Python scripting for GIMP. My script in the first show about scripting was simple, just saving some clicks. Now it is more complicated, variables, loops and floating points included. But no parrots!

You find a better version of the programs in the companion file. Following a tip in our Forum I included a Undo Group. So the action can be undone, a behaviour that should have been included from the start.

I mentioned some sources. Instant Python, the official Python Tutorial and the GIMP Python reference. Bert has a script page and a much better version of the Octave sharpening script.

Then we have a UnGIMP composition challenge on the Forum.

Have I forgotten some promised links? Please complain below!

Errata:

The loop counter in the companion file is set to 6 instead of 4. You can change it back or leave it.

Perhaps it is better to take the image size from drw instead of img. See the discussion in the forum. drw.height and drw.width should work also when the layer is smaller than the image.

Creative Commons License
Meet the GIMP Video Podcast by Rolf Steinort and Philippe Demartin is licensed under a Creative Commons Attribution-Share Alike 3.0 Germany License.
Permissions beyond the scope of this license may be available at http://meetthegimp.org.

38 thoughts on “Episode 129: Octave Sharpening Python Plugin

  1. Watching through the last issues I notice You not finished the Pimp competition. You took Philips winner in pieces but not Yours. It was written the colour change can be automatic made. I really like to see this. I try to change some photos like this but it does not work. Some vital step is not there.
    Please forgive my bad english.

  2. In the video you set loops = 4 but in the downloadable example loops = 6. Did you put 6 loops in for any special reason, please?

  3. Norman, I forgot to put it back after my experiments. I also tried 6 iterations (that scene didn’t made it into the show) and didn’t take the change back. I’ll correct it on the server.

    Sandra, I haven’t specially discussed the image of the book winner because there were technically more interesting images. The winner was selected by chance, the reviewed images by my bias.
    I’ll explain it in one of the next shows.

  4. Thanks for the explanation, easily done. I tried to get to grips with Python 2 or 3 years ago but I found it quite difficult to get my brain around once I got past the basics. Anno Domini I expect.

  5. I like this show. It is just fun watching you explaining things. Even such “dry” stuff (if this word is used in English too). After this show I nearly think, that I could do a script by myself ;-)

    Python seems to have a lot more capabilities, but I however prefer the simple record-function in other programs, which work like a tape-recorder. They are a lot easier to use, but of course not as versatile as python. Is there any chance, that this could be included in some following versions of Gimp?

  6. @mramshaw: Thanks for the links and the pronunciation update. The explanation in the second link about drawables is simply hilarious! :-)

    @Fornit: A tape recorder interface would be great and I think it will be integrated as soon as it is possible. As I have understood the Gurus just now there is no single point to put your microphone in for recording. GEGL is supposed to solve that problem (as all others, colour depth, world peace and climate change. ;-) )

  7. @Rolf: Sorry to be a nuisance but the downloaded script does not work the same as the one you demonstrated. For some reason, the image changes to black & white and then goes ahead and sharpens as it should. What do I need to change, please?

  8. Well, I should have debugged it with a coloured image, my test case was a monochrome one. So it works the same way as in the show, but I failed to test it in the show thoroughly. Seems we are in for a debugging and testing primer next show. ;-)

    I have an idea what the source of the error can be: Layer modes. But I haven’t checked yet.

  9. Pingback: Links 13/12/2009: Preview of Linux 2.6.33, Krita Gets €4,000 | Boycott Novell

  10. I wish load bird image. Image needs very longer and not open me. I fetch not remember type file and he crash. Is there no allow? How not with that? One do that image blur on behind? And one bird unblur?

  11. Reference by bird of white image behind. I that wish load image. Image needs very longer load the time. Open fetch not remember type file. After he crash. Which way without that? One do bird unblur. The make behind blur? How below divide?

  12. Pingback: Octave Sharpening Python Plugin-Meet The Gimp « LawnGnomeDeathMarch

  13. @Shiro: This one?
    Just click on the thumbnail, it will bring you to 23, the image hoster. You can download it there, even the original size is there. Look for “More sizes for sharing” on the right side.

    This image was not processed in GIMP, it is just out of the camera.

  14. Is there a way to use this on a lot of photos all at once? Sharpen everyone takes a very long time.

    And the bird photo is a fake. It shows in the unsharp copy back and the sharp bird. In nature both are unsharp or sharp.

  15. I would be a bit more cautious with calling an image a fake. I see it as an insult.

    It has a shallow DoF, so the bird is in focus and the twigs are in the background out of focus.

  16. It is not unsult. Only experts can photograph flying bird. It is very hard. You cant do that self. Maybe YOU can but normal people cant. Waiting days and weeks for one photo is expensive and work. Experts sell photos not give away. But normal people take small model bird before white paper and copy another behind. I did this it looks the same. It is very easy. But you can see the not sharp behind from the copy. So you discover it.
    The bird is mew or skua not dof. Dof is larger and other feather.

  17. Ulf, do you know anything of the stuff you are talking about?
    Just because YOU are not able to shoot a bird it doesn’t mean everybody is unable. It isn’t too difficult if you know how to set up your camera. But it seems you don’t what to learn that (or anything else as e.g. the depth of field problem) but prefer wasting your time insulting people instead. It’s your choice but we won’t tolerate that here for too long…!
    The most stupid sentence is your last one – if you are really that clever you would know that DOF can look in a thousand different ways. From almost no blur to totally blurred. From circled bokeh to any figure you want.

    If you want to learn and discuss in a tolerating way, feel free to join the forum. If you just want to abuse and insult, you won’t find the right place here (it’s not much effort putting you on the spam list)…

  18. Ulf, the photographer took 400 images and this one was the one. The rest went into the bin. I said that in the podcast and you can find it in the forum entry.

    DoF is not a kind of bird, it is Depth of Field. Check the term in Wikipedia or a photography book. The bird is very common in Germany and looks for food where people are. So it’s easy to find and photograph because they stay and wait for you to drop some food. If you take enough images with the right kind of camera you get them good. And a DSLR and a zoom are not special these days.

  19. DoF, dove?? This is a seagull of whatever exact kind, and those birds are definitely not shy (I once had to rescue my cam from a curious gull).

    Have a nice and peaceful Advent season!

  20. Ok, maybe this will calm the waves: I wrote 400 shots, but these are the ones I took on Friday. I didn’t count those from Wednesday and Thursday because it is somewhat embarrassing to admit it took me 3 days just to capture one bird. I’ll upload the third photo of the seagull to the photogroup so you can easily see it’s real (because the fringe of the penguin area is visible). Shooting flying birds or leaping large cats is not that hard, especially as a regular visitor to the zoo. You have to watch for a while to anticipate its moves and autodrive will take care of the rest. Rolf coined this “the machinegunner’s approach to photography”. I like this term. ;-)
    It’s not like I’m the only one taking shots of the seagulls, especially as their thieving behavior is a regular topic in the zoo’s tv show. During commented feeding there are always people trying to capture them with their p&s, which is an almost hopeless undertaking. The lcd lag means you have to shoot in advance and the irregular shutter lag due to autofocus and scene detection and slow series speed makes it almost impossible. You see more people swearing and cursing than in politics. And unfortunately many people don’t know that there is more to photography than p&s instant click and don’t understand what happens if you widen your aperture or manually focus out-of-center. On more than one occasion I had people asking me, after they caught a glimpse on my lcd, how I got the picture back into the camera after editing it. They don’t understand it’s the shot I just took even though they stood right next to me as I took it.
    I use a lowend camera and cheap lenses but imagine what Rolf experiences with his big d200. I guess he has to lug a heap of business cards around wherever he goes… ;-)

  21. Hehe, thanks for that little story! Sometimes it’s really like this. Once I was at the biathlon world cup in Oslo/ Norway. Just as a visitor. But the security asked if they should tear down the fences so I could shoot better images. Of course I agreed :D
    Sometimes the camera opens doors and picks up with somebody ;)

  22. It is not too hard to make good shots of animals. For example, I never managed to get a good picture of a squirrel. But in some cities they live in the parks and are fed by the people and nearly tame.

    I made a portrait of a raven (not in the air ;-) ) in dresden. This is quite impossible where I live, but in bigger cities they are use to people and let them get closer.

    So every shot is possible by nearly everyone. You must have decent equipment and you have to know where, when and how. The first you get in every camerastore, the rest on the internet.

    Than you have to take your time and discomfort and try it a few times. Maybe you have to travel, or you have to get up very early and so on.

  23. Thanks for the episode. I am now very encouraged to try my hand at scripting!

    I studied Rolf’s script, and I have a question about opacity. Is the goal is to have each sharpening layer contribute equally to the result? If so, then successive division by two doesn’t work.

    Of course if you have two layers,it does work, since each layer contributes 1/2 to the result. But suppose you have three layers. Then the top layer contributes 1/4 and the bottom two layers split the remainder (3/4), giving each a 3/8 contribution. In this case, each of the bottom two layers contributes more than the top layer.

    Again, I am not sure that equal contributions is the goal, but if so, successive opacities should be calculated as one over the loop index, i.e. 1/1, 1/2, 1/3, 1/4, etc.

    To see how this corrects the problem, again consider three layers. The top layer contributes 1/3 and the bottom two layers split the remainder (2/3), giving each a 1/3 contribution. With four layers, the top layer contributes 1/4, the next-to-top layer contributes 1/3 of the remainder (1/3 x 3/4 = 1/4), and the bottom two layers again split the remainder (1/2 x 1/2 = 1/4).

    If the goal is to have UNequal contributions, then it would be interesting to hear the technical argument behind the way contributions are allocated.

  24. Ah, I see you are right. As the Unsharp mask radius increases, we want its effect to be less, and decreasing opacity accomplishes that.

  25. It’s always fun to do some programming with Python. To become a bit more advanced you should try to write your programs more “pythonesque”, i.e. to adapt to the style used by the Python community. So I would suggest not to use the while-loop with a loop counter but instead the for-loop together with the range-function:

    for i in range(0,5):
         print i

    This will print the numbers from 0 to 4. range includes the first parameter and excludes the second. The big advantage is that you cannot forget about incrementing the loop counter and the you have separated the loop stuff from the things you want to do inside the loop.

  26. I just bought a Python book and will work through it. I indentet your posting, with a couple of &-nbsp-; without the dashes. Some HTML does work.

    I wanted to use for in the beginning, but could not remeber how to do this in Python. I did a bit for the Arduino in a kind of C before and was cvompletely off track.

  27. Thank you for fixing the indentation. Another great book on Python is “Dive into Python”. Especially nice is that you can buy it or read it online: http://diveintopython.org/

    There is one catch with Python nowadays. With version 3 a lot of things changed. So when you try some examples be careful that those examples fit to your Python version.

  28. Pingback: Цифровая фотография - » MTG: Эпизоды 4 квартала 2009

Anything to add from your side of the computer?