Converting image into graphics

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
9
down vote

favorite
1












I have a black-white image, but it is rather blurry so I was thinking of converting it into vector graphics so I could do some coloring. This is the image:



img = Import["https://i.stack.imgur.com/cyHjC.jpg"];


Source image



I used Binarize with ImageGraphics, but the result is not so good:



img2 = Binarize[ImageApply[If[Mean@# < 0.9, #, 1, 1, 1] &, img], 0.8]
ImageGraphics[Erosion[img2, 1], 2, Method -> "LinearSeparable", 10]


enter image description here



As you can see, the lines are pretty rough with weird curves here and there.



ImageGraphics tends to deal with much more complicated stuff, so I thought maybe it is possible to optimize this with the knowledge that this is a black and white image with only the lines required. But how?










share|improve this question























  • Could you post the image here directly?
    – Carl Lange
    4 hours ago










  • @CarlLange edited, thanks.
    – t-smart
    4 hours ago










  • It doesn't look very blurry to me. What kind of coloring is it that you want to do?
    – C. E.
    3 hours ago






  • 1




    Hm. I usually don't suggest to use external programs but I've just tried it with Inkscape (import the image, go to "Path" -> "Trace bitmap", and use "Brightness cutoff" 0.8). It was easy as cake.
    – Henrik Schumacher
    2 hours ago











  • What is this image? It's nice and I collect such graphics, so I am just curious.
    – Vitaliy Kaurov
    41 mins ago














up vote
9
down vote

favorite
1












I have a black-white image, but it is rather blurry so I was thinking of converting it into vector graphics so I could do some coloring. This is the image:



img = Import["https://i.stack.imgur.com/cyHjC.jpg"];


Source image



I used Binarize with ImageGraphics, but the result is not so good:



img2 = Binarize[ImageApply[If[Mean@# < 0.9, #, 1, 1, 1] &, img], 0.8]
ImageGraphics[Erosion[img2, 1], 2, Method -> "LinearSeparable", 10]


enter image description here



As you can see, the lines are pretty rough with weird curves here and there.



ImageGraphics tends to deal with much more complicated stuff, so I thought maybe it is possible to optimize this with the knowledge that this is a black and white image with only the lines required. But how?










share|improve this question























  • Could you post the image here directly?
    – Carl Lange
    4 hours ago










  • @CarlLange edited, thanks.
    – t-smart
    4 hours ago










  • It doesn't look very blurry to me. What kind of coloring is it that you want to do?
    – C. E.
    3 hours ago






  • 1




    Hm. I usually don't suggest to use external programs but I've just tried it with Inkscape (import the image, go to "Path" -> "Trace bitmap", and use "Brightness cutoff" 0.8). It was easy as cake.
    – Henrik Schumacher
    2 hours ago











  • What is this image? It's nice and I collect such graphics, so I am just curious.
    – Vitaliy Kaurov
    41 mins ago












up vote
9
down vote

favorite
1









up vote
9
down vote

favorite
1






1





I have a black-white image, but it is rather blurry so I was thinking of converting it into vector graphics so I could do some coloring. This is the image:



img = Import["https://i.stack.imgur.com/cyHjC.jpg"];


Source image



I used Binarize with ImageGraphics, but the result is not so good:



img2 = Binarize[ImageApply[If[Mean@# < 0.9, #, 1, 1, 1] &, img], 0.8]
ImageGraphics[Erosion[img2, 1], 2, Method -> "LinearSeparable", 10]


enter image description here



As you can see, the lines are pretty rough with weird curves here and there.



ImageGraphics tends to deal with much more complicated stuff, so I thought maybe it is possible to optimize this with the knowledge that this is a black and white image with only the lines required. But how?










share|improve this question















I have a black-white image, but it is rather blurry so I was thinking of converting it into vector graphics so I could do some coloring. This is the image:



img = Import["https://i.stack.imgur.com/cyHjC.jpg"];


Source image



I used Binarize with ImageGraphics, but the result is not so good:



img2 = Binarize[ImageApply[If[Mean@# < 0.9, #, 1, 1, 1] &, img], 0.8]
ImageGraphics[Erosion[img2, 1], 2, Method -> "LinearSeparable", 10]


enter image description here



As you can see, the lines are pretty rough with weird curves here and there.



ImageGraphics tends to deal with much more complicated stuff, so I thought maybe it is possible to optimize this with the knowledge that this is a black and white image with only the lines required. But how?







graphics image-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago









C. E.

47.9k391193




47.9k391193










asked 6 hours ago









t-smart

783113




783113











  • Could you post the image here directly?
    – Carl Lange
    4 hours ago










  • @CarlLange edited, thanks.
    – t-smart
    4 hours ago










  • It doesn't look very blurry to me. What kind of coloring is it that you want to do?
    – C. E.
    3 hours ago






  • 1




    Hm. I usually don't suggest to use external programs but I've just tried it with Inkscape (import the image, go to "Path" -> "Trace bitmap", and use "Brightness cutoff" 0.8). It was easy as cake.
    – Henrik Schumacher
    2 hours ago











  • What is this image? It's nice and I collect such graphics, so I am just curious.
    – Vitaliy Kaurov
    41 mins ago
















  • Could you post the image here directly?
    – Carl Lange
    4 hours ago










  • @CarlLange edited, thanks.
    – t-smart
    4 hours ago










  • It doesn't look very blurry to me. What kind of coloring is it that you want to do?
    – C. E.
    3 hours ago






  • 1




    Hm. I usually don't suggest to use external programs but I've just tried it with Inkscape (import the image, go to "Path" -> "Trace bitmap", and use "Brightness cutoff" 0.8). It was easy as cake.
    – Henrik Schumacher
    2 hours ago











  • What is this image? It's nice and I collect such graphics, so I am just curious.
    – Vitaliy Kaurov
    41 mins ago















Could you post the image here directly?
– Carl Lange
4 hours ago




Could you post the image here directly?
– Carl Lange
4 hours ago












@CarlLange edited, thanks.
– t-smart
4 hours ago




@CarlLange edited, thanks.
– t-smart
4 hours ago












It doesn't look very blurry to me. What kind of coloring is it that you want to do?
– C. E.
3 hours ago




It doesn't look very blurry to me. What kind of coloring is it that you want to do?
– C. E.
3 hours ago




1




1




Hm. I usually don't suggest to use external programs but I've just tried it with Inkscape (import the image, go to "Path" -> "Trace bitmap", and use "Brightness cutoff" 0.8). It was easy as cake.
– Henrik Schumacher
2 hours ago





Hm. I usually don't suggest to use external programs but I've just tried it with Inkscape (import the image, go to "Path" -> "Trace bitmap", and use "Brightness cutoff" 0.8). It was easy as cake.
– Henrik Schumacher
2 hours ago













What is this image? It's nice and I collect such graphics, so I am just curious.
– Vitaliy Kaurov
41 mins ago




What is this image? It's nice and I collect such graphics, so I am just curious.
– Vitaliy Kaurov
41 mins ago










1 Answer
1






active

oldest

votes

















up vote
5
down vote













Your image is too small, so post-processing algorithms run into a lot of errors as initial information is tiny. Right form the start significantly resize image (upsample) trying to "guess" what info in the image is missing. As you are using original image



i = Import["https://i.stack.imgur.com/cyHjC.jpg"]


to do this before post-processing ImageResize will do a great job as it will have all available info. The lesson here is: do not upsample after some post-processing stages as some info is getting lost during these operations. BTW ImageResize generally upsamples nicely in my experience. Now both Binarize and ImageGraphics will have much more "room" to work and you get a very high quality vector:



ImageGraphics[Binarize[ImageResize[i, 2000], .8],2,Method -> "Exact"]


You can export it into a vector format



Export["vector.SVG", vector]


but because Stack Exchange cannot render .SVG (unfortunately) I uploaded it for you HERE and below is a raster copy. Now you can play further various improvement routs found in Image Restoration and other guides, but the key point is to increase image resolution from the start.



enter image description here






share|improve this answer






















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183174%2fconverting-image-into-graphics%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    Your image is too small, so post-processing algorithms run into a lot of errors as initial information is tiny. Right form the start significantly resize image (upsample) trying to "guess" what info in the image is missing. As you are using original image



    i = Import["https://i.stack.imgur.com/cyHjC.jpg"]


    to do this before post-processing ImageResize will do a great job as it will have all available info. The lesson here is: do not upsample after some post-processing stages as some info is getting lost during these operations. BTW ImageResize generally upsamples nicely in my experience. Now both Binarize and ImageGraphics will have much more "room" to work and you get a very high quality vector:



    ImageGraphics[Binarize[ImageResize[i, 2000], .8],2,Method -> "Exact"]


    You can export it into a vector format



    Export["vector.SVG", vector]


    but because Stack Exchange cannot render .SVG (unfortunately) I uploaded it for you HERE and below is a raster copy. Now you can play further various improvement routs found in Image Restoration and other guides, but the key point is to increase image resolution from the start.



    enter image description here






    share|improve this answer


























      up vote
      5
      down vote













      Your image is too small, so post-processing algorithms run into a lot of errors as initial information is tiny. Right form the start significantly resize image (upsample) trying to "guess" what info in the image is missing. As you are using original image



      i = Import["https://i.stack.imgur.com/cyHjC.jpg"]


      to do this before post-processing ImageResize will do a great job as it will have all available info. The lesson here is: do not upsample after some post-processing stages as some info is getting lost during these operations. BTW ImageResize generally upsamples nicely in my experience. Now both Binarize and ImageGraphics will have much more "room" to work and you get a very high quality vector:



      ImageGraphics[Binarize[ImageResize[i, 2000], .8],2,Method -> "Exact"]


      You can export it into a vector format



      Export["vector.SVG", vector]


      but because Stack Exchange cannot render .SVG (unfortunately) I uploaded it for you HERE and below is a raster copy. Now you can play further various improvement routs found in Image Restoration and other guides, but the key point is to increase image resolution from the start.



      enter image description here






      share|improve this answer
























        up vote
        5
        down vote










        up vote
        5
        down vote









        Your image is too small, so post-processing algorithms run into a lot of errors as initial information is tiny. Right form the start significantly resize image (upsample) trying to "guess" what info in the image is missing. As you are using original image



        i = Import["https://i.stack.imgur.com/cyHjC.jpg"]


        to do this before post-processing ImageResize will do a great job as it will have all available info. The lesson here is: do not upsample after some post-processing stages as some info is getting lost during these operations. BTW ImageResize generally upsamples nicely in my experience. Now both Binarize and ImageGraphics will have much more "room" to work and you get a very high quality vector:



        ImageGraphics[Binarize[ImageResize[i, 2000], .8],2,Method -> "Exact"]


        You can export it into a vector format



        Export["vector.SVG", vector]


        but because Stack Exchange cannot render .SVG (unfortunately) I uploaded it for you HERE and below is a raster copy. Now you can play further various improvement routs found in Image Restoration and other guides, but the key point is to increase image resolution from the start.



        enter image description here






        share|improve this answer














        Your image is too small, so post-processing algorithms run into a lot of errors as initial information is tiny. Right form the start significantly resize image (upsample) trying to "guess" what info in the image is missing. As you are using original image



        i = Import["https://i.stack.imgur.com/cyHjC.jpg"]


        to do this before post-processing ImageResize will do a great job as it will have all available info. The lesson here is: do not upsample after some post-processing stages as some info is getting lost during these operations. BTW ImageResize generally upsamples nicely in my experience. Now both Binarize and ImageGraphics will have much more "room" to work and you get a very high quality vector:



        ImageGraphics[Binarize[ImageResize[i, 2000], .8],2,Method -> "Exact"]


        You can export it into a vector format



        Export["vector.SVG", vector]


        but because Stack Exchange cannot render .SVG (unfortunately) I uploaded it for you HERE and below is a raster copy. Now you can play further various improvement routs found in Image Restoration and other guides, but the key point is to increase image resolution from the start.



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 41 mins ago

























        answered 1 hour ago









        Vitaliy Kaurov

        56k6156274




        56k6156274



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183174%2fconverting-image-into-graphics%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke