照片/图片到草图算法草图、算法、照片、图片

2023-09-12 01:14:24 作者:回不去的过去

有没有人有一个想法,链接,库,源$ C ​​$ C,...如何转换照片的和图像(位图)来粗略样的照片?我无法找到如何做到这一点任何的良好来源。

Does anyone have an idea, link, library, source code, ... on how to convert photo's and images (bitmaps) to sketchy-like pictures? I can't find any good sources on how to do it.

我发现这个链接如何卡通IFY的图像编程?有关如何卡通IFY一个图像编程,但我preFER,使其图像到草图之一。

I found this link How to cartoon-ify an image programmatically? about how to cartoon-ify a image programmatically, but i prefer to make it image-to-sketch one.

我想打一个Android应用程序,可以通过编程方式转换的JPEG照片的,以粗略的图像。

I want to make an android app that can programmatically "convert" JPEG photo's to sketchy images.

推荐答案

好了,我发现使用不同的技术我自己的答案像马克告诉我的。 我用下面的伪code:

Ok, so i found my own answer using different techniques like Mark told me. I use the following pseudocode:

*s = Read-File-Into-Image("/path/to/image")
*g = Convert-To-Gray-Scale(s)
*i = Invert-Colors(g)
*b = Apply-Gaussian-Blur(i)
*result = Color-Dodge-Blend-Merge(b,g)

第一种方法是容易在互联网上找到,但在最后一个我无法找到很多信息,甚至没有源$ C ​​$ C。所以,我搜索了PS是如何做到的,发现C ++以下公式:

The first four methods were easily to find on the internet, however on the last one I couldn't find a lot of information, not even source code. So I searched on how PS did it and found the following formula in c++:

((uint8)((B == 255) ? B:min(255, ((A << 8 ) / (255 - B)))))

然后我把它转换成Java具有以下code:

Then i converted it to Java with the following code:

private int colordodge(int in1, int in2) {
    float image = (float)in2;
    float mask = (float)in1;
    return ((int) ((image == 255) ? image:Math.min(255, (((long)mask << 8 ) / (255 - image)))));

}

/**
 * Blends 2 bitmaps to one and adds the color dodge blend mode to it.
 */
public Bitmap ColorDodgeBlend(Bitmap source, Bitmap layer) {
    Bitmap base = source.copy(Config.ARGB_8888, true);
    Bitmap blend = layer.copy(Config.ARGB_8888, false);

    IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
    base.copyPixelsToBuffer(buffBase);
    buffBase.rewind();

    IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
    blend.copyPixelsToBuffer(buffBlend);
    buffBlend.rewind();

    IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
    buffOut.rewind();

    while (buffOut.position() < buffOut.limit()) {
        int filterInt = buffBlend.get();
        int srcInt = buffBase.get();

        int redValueFilter = Color.red(filterInt);
        int greenValueFilter = Color.green(filterInt);
        int blueValueFilter = Color.blue(filterInt);

        int redValueSrc = Color.red(srcInt);
        int greenValueSrc = Color.green(srcInt);
        int blueValueSrc = Color.blue(srcInt);

        int redValueFinal = colordodge(redValueFilter, redValueSrc);
        int greenValueFinal = colordodge(greenValueFilter, greenValueSrc);
        int blueValueFinal = colordodge(blueValueFilter, blueValueSrc);

        int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal);

        buffOut.put(pixel);
    }

    buffOut.rewind();

    base.copyPixelsFromBuffer(buffOut);
    blend.recycle();

    return base;
}

如果在code可以改善,请发布一个新的答案或下面的评论。谢谢!

If the code could be improved, please post a new answer or comment below. Thanks!