Coder Social home page Coder Social logo

Delegated pixel-processing effect about mmalsharp HOT 5 OPEN

MV10 avatar MV10 commented on June 16, 2024
Delegated pixel-processing effect

from mmalsharp.

Comments (5)

MV10 avatar MV10 commented on June 16, 2024

A related idea: it may also be interesting to look at generalizing the cell-level processing into a delegate approach. If the call overhead isn't too terrible, changes like the convolution code in PR #175 could perhaps just turn into an implementation of that. Although I'll be surprised if the framework doesn't add a lot of overhead. Even so, a cell-level delegate might be interesting, too, even if it's faster to hard-code it internally as the PR does.

from mmalsharp.

MV10 avatar MV10 commented on June 16, 2024

Possibly related to #82

from mmalsharp.

MV10 avatar MV10 commented on June 16, 2024

I'm playing around with this and a per-pixel delegate is about as fast as the convolution processing -- delegate invocation overhead doesn't seem to be a big problem. We're about to take a vacation but I should have something on this around the middle of next week.

However, I'm realizing the CloneToRawBitmap method I wrote for convolution also results in a BGR buffer, so Bitmap's channel-mixup works in the other direction as well. This means we have two scenarios.

Scenario 1 is when the original context is raw. The data is RGB and we must do the red/blue swap before saving.

Scenario 2 is when the original context is encoded. We need raw data, but Bitmap is returning that as BGR -- and to re-encode, it needs to stay BGR. So instead of swapping twice, we can use an array index offset to point to the red and blue channels and process them in place.

A bit of a headache.

from mmalsharp.

MV10 avatar MV10 commented on June 16, 2024

Here's a vignette delegate (linear, so a bit crude), runs in about 500 ms on a 1296 x 972. (v1 mode4) image:

context.Apply(new CustomPixelProcessor((r, g, b, x, y, w, h) =>
{
    var xc = w / 2;
    var yc = h / 2;
    var point = Math.Sqrt(Math.Pow(x - xc, 2) + Math.Pow(y - yc, 2));
    var center = Math.Sqrt(Math.Pow(xc, 2) + Math.Pow(yc, 2));
    var dist = 1.0f - (point / center);
    return ((int)(r * dist), (int)(g * dist), (int)(b * dist));
}));

And a grayscale delegate runs in about 340 ms:

context.Apply(new CustomPixelProcessor((r, g, b, x, y) =>
{
    var i = (int)((r * 0.299f) + (g * 0.587f) + (b * 0.114f));
    return (i, i, i);
}));

Users will have to be careful about thread safety, though. I'm thinking about a couple of ways to allow the user to pass arbitrary data to the delegate but I need to review how to make it thread safe -- I think I can use a generic struct param but I need to double check some assumptions.

From here I think the cell-based delegate will be relatively trivial.

I should really go pack my luggage, though. 😬

Vignette of my office (excuse the mess, we're moving house)...

snapshot

from mmalsharp.

MV10 avatar MV10 commented on June 16, 2024

If you want to have a look at the work-in-progress while I'm out of town, I moved convolutions to a separate folder and put much of the common logic into a base class. The cell-based delegate is currently stubbed until I get back, but:

https://github.com/MV10/MMALSharp/tree/image_fx_delegates/src/MMALSharp.Processing/Processors/Effects

The vignette implementation using a custom metadata struct:

https://github.com/MV10/pi-cam-test/blob/local_mmal_dev_pkg/Program.cs#L854

https://github.com/MV10/pi-cam-test/blob/local_mmal_dev_pkg/VignetteMetadata.cs

from mmalsharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.