FourthWorld wrote:hairydalek wrote:Achieving effects such as blurs, adding noise, and manipulating contrast seems to require code that steps through an image pixel by pixel. This means that if you are using a slider to alter the amount of that effect, you can’t provide live feedback in the form of a preview, and you need to wait a long time for the image to process when the slider drag has ended. A very long time if we are talking about blurs. Tea-making lengths of time. If someone then decides to alter the size of the image, change its crop, the processing has to be repeated.
You have discovered a use case for which most scripting language are of limited utility.
For effects LiveCode has built-in support for which was written in C, we have the pleasure of invoking that with nearly instantaneous results. These currently include opacity, inner glow, outer glow, color overlay, transfer modes, drop shadows, and others.
But there are still some image manipulations. like blur and noise, which do not have C-borne code in the engine, and so like any other scripting language the ovehead of doing such low-level work in a high-level language will add up quickly with larger images.
If you search the request queue for "image" you'll find a variety of enhancement requests for various things, but one which may be most useful I was unable to find there: a generic convolver.
I haven't done much image processing myself so forgive me if my ignorance shows, but it seems many of the operations we'd like to do not already supported could be handled through a convolver, and the problem being that applying a matrix change to the full set of pixels in script is currently computationally prohibitive in script.
But if we have something like a convolve function, which could take a matrix of deltas and a set of image data and return the image data altered according to that matrix, because most of the work would be done in C it should be very efficient while still being reasonably flexible.
If that hunch is correct, perhaps we could put together a bounty so someone in the community might consider adapting publicly-available code for this to LC. At a minimum it could be an external, but even better if it became a pull request for an engine feature.
I believe a convolver would handle noise, but would it handle blur as well?
Thanks. Yes, I get the difference between scripting and working in languages like C (similar relationship to BASIC and assembler on my trusty old BBC B) - though the latter (in both cases) is beyond me. I don’t fully understand how convolving filters work, though I have been reading up on blurs and other filters in order to see if I can grasp what’s needed, and that’s helping improve my understanding a bit. There’s one where the writer asks if he needs a haircut and uses image processing to determine that, and there are other tutorials which have helped. I also found some reference with pseudocode that helped me put greyscale and contrast adjustments together, but, as you’ll guess, they are all a pixel by pixel walk-through in LC’s scripting language.
http://www.dfstudios.co.uk/articles/pro ... lgorithms/
If by a convolver you mean “pass a matrix of values to a function that processes an image using it” then it seems that, yes, blurs are possible:
http://lodev.org/cgtutor/filtering.html
That page shows that sharpening, embossing and other effects are possible. I need to study that a bit more. I’ll have a stab at writing my own LC function to process and image from a matrix. I know it will be slow, but the exercise may be helpful to me. Being able to pass data to a function in LC and get back results faster would, of course, be far better and make the application much more efficient.
I’ll explain a little about my thinking for what I am working on, just so you know where I’m coming from.
I know what I can do in Photoshop to achieve an effect, and if I don’t know, I know where to look for examples. I am trying to replicate those kind of things in LiveCode. I went from thinking about applying fairly simple effects like contrast, greyscale and brightness (slow, but bearable) to pondering creating effects similar to Instagram and other apps. Basically, applying what in Photoshop is referred to as “filters” (blur, noise, etc.), colour tints, or just overlaying an image with a colour gradient, layering them and grabbing the output.
For example, to create a Holga style lens effect, you do this:
1 - Get your original image, duplicate it and place the duplicate over the top of the original
2 - Apply a radial blur to the image. I’m not sure how you’d achieve this using the convolution method above. I guess a regular of gaussian blur may be sufficient, but Holga lenses do do weird distortions which the radial blur emulates better.
3 - Using an alpha channel, make the blurred image transparent at the middle and gradually increase the opacity towards the edges
4 - (Optional) Greyscale and contrast applied to both images
If you want a more detailed step by step for this example, this tutorial is what I was thinking about:
https://lenscraft.co.uk/how-to-digitall ... lga-image/
I know how to do this in LiveCode, and (apart from the radial blur - I’d use a standard blur for the moment) I expect I can get the effects I want. Right now, as you know, it’s a time penalty that’s thwarting me.
It’s a hideous case of “function creep” but this project started off as a “can I” question as I’ve not done much in LiveCode, and so far I’ve been able to answer with a “yes”. As I progress, more questions arise.
I am writing an application that processes images shot with a digital stereo camera and makes them into a printable Holmes Card (a popular way of presenting stereo photos from Victorian times). There are a few apps around that do this already, but I’m finding them limiting. I want to be able to do more in the application, rather than duck out into Photoshop, or make various design choices about the card itself that other apps don’t offer. So I decided to have a go myself. It’s a personal project at the moment, but slowly developing a life of its own. It’s been a fun thing to attempt, and I’ve learned quite a bit about LiveCode (and, indeed a small bit about image processing).