Code Monkey home page Code Monkey logo

paintbynumbersgenerator's Introduction

Paint by numbers generator

Generate paint by number images (vectorized with SVG) from any input image.

Demo

Try it out here

CLI Version

The CLI version is a self contained node application that does the conversion from arguments, for example:

paint-by-numbers-generator-win.exe -i input.png -o output.svg

You can change the settings in settings.json or optionally specify a specific settings.json with the -c path_to_settings.json argument.

The settings contain mostly the same settings in the web version:

  • randomSeed: the random seed to choose the initial starting points of the k-means clustering algorithm. This ensures that the same results are generated each time.

  • kMeansNrOfClusters: the number of colors to quantize the image to

  • kMeansMinDeltaDifference: the threshold delta distance of the k-means clustering to reach before stopping. Having a bigger value will speed up the clustering but may yield suboptimal clusters. Default 1

  • kMeansClusteringColorSpace: the color space to apply clustering in

  • kMeansColorRestrictions: Specify which colors should be used. An array of rgb values (as number array) or names of colors (reference to color aliases). If no colors are specified no restrictions are applied. Useful if you only have a few colors of paint on hand.

  • colorAliases: map of key/values where the keys are the color names and the values are the rgb colors (as number array). You can use the color names in the color restrictions above. The names are also mentioned in the output json that tells you how much % of the area is of that specific color. "colorAliases": { "A1": [ 0, 0, 0 ], "A2": [ 255, 0, 0 ], "A3": [ 0, 255, 0 ], }

  • removeFacetsSmallerThanNrOfPoints: removes any facets that are smaller than the given amount of pixels. Lowering the value will create more detailed results but might be much harder to actually paint due to their size.

  • removeFacetsFromLargeToSmall (true/false): largest to smallest will prevent boundaries from warping the shapes because the smaller facets act as border anchorpoints but can be considerably slower

  • maximumNumberOfFacets: if there are more facets than the given maximum number, keep removing the smallest facets until the limit is reached

  • nrOfTimesToHalveBorderSegments: reducing the amount of points in a border segment (using haar wavelet reduction) will smooth out the quadratic curve more but at a loss of detail. A segment (shared border with a facet) will always retain its start and end point.

  • narrowPixelStripCleanupRuns: narrow pixel cleanup removes strips of single pixel rows, which would make some facets have some borders segments that are way too narrow to be useful. The small facet removal can introduce new narrow pixel strips, so this is repeated in a few iterative runs.

  • resizeImageIfTooLarge (true/false): if true and the input image is larger than the given dimensions then it will be resized to fit but will maintain its ratio.

  • resizeImageWidth: width restriction

  • resizeImageHeight: height restriction

There are also output profiles that you can define to output the result to svg, png, jpg with specific settings, for example:

  "outputProfiles": [
        {
            "name": "full",
            "svgShowLabels": true,
            "svgFillFacets": true,
            "svgShowBorders": true,
            "svgSizeMultiplier": 3,
            "svgFontSize": 50,
            "svgFontColor": "#333",
            "filetype": "png"
        },
        {
            "name": "bordersLabels",
            "svgShowLabels": true,
            "svgFillFacets": false,
            "svgShowBorders": true,
            "svgSizeMultiplier": 3,
            "svgFontSize": 50,
            "svgFontColor": "#333",
            "filetype": "svg"
        },
        {
            "name": "jpgtest",
            "svgShowLabels": false,
            "svgFillFacets": true,
            "svgShowBorders": false,
            "svgSizeMultiplier": 3,
            "svgFontSize": 50,
            "svgFontColor": "#333",
            "filetype": "jpg",
            "filetypeQuality": 80
        }
    ]

This defines 3 output profiles. The "full" profile shows labels, fills the facets and shows the borders with a 3x size multiplier, font size weight of 50, color of #333 and output to a png image. The bordersLabels profile outputs to a svg file without filling facets and jpgtest outputs to a jpg file with jpg quality setting of 80.

The CLI version also outputs a json file that gives more information about the palette, which colors are used and in what quantity, e.g.:

  ...
  {
    "areaPercentage": 0.20327615489130435,
    "color": [ 59, 36, 27 ],
    "frequency": 119689,
    "index": 0
  },
   ...

The CLI version is useful if you want to automate the process into your own scripts.

Screenshots

Screenshot

Screenshot

Example output

ExampleOutput

ExampleOutput2

Running locally

I used VSCode, which has built in typescript support. To debug it uses a tiny webserver to host the files on localhost.

To run do npm install to restore packages and then npm start to start the webserver

Compiling the cli version

Install pkg first if you don't have it yet npm install pkg -g. Then in the root folder run pkg .. This will generate the output for linux, windows and macos.

paintbynumbersgenerator's People

Contributors

dependabot[bot] avatar drake7707 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paintbynumbersgenerator's Issues

uf.readBigUInt64LE is not a function

Full error:

pkg cli.js
> [email protected]
> Targets not specified. Assuming:
  node10-linux-x64, node10-macos-x64, node10-win-x64
> Error! TypeError: buf.readBigUInt64LE is not a function
    at patchCommand (/usr/local/lib/node_modules/pkg/lib-es5/mach-o.js:17:33)
    at patchMachOExecutable (/usr/local/lib/node_modules/pkg/lib-es5/mach-o.js:41:9)
    at exec (/usr/local/lib/node_modules/pkg/lib-es5/index.js:515:63)

The program works fine in node, and my program doesn't use any special big numbers or the readBigUInt64LE function, so I have no idea why this is happening, but I'm assuming it's something to do with how pkg internally represents data.

Color Problem

hello, how to reduce the number of color shades.
And see the different shades available?
thank you

to load custome saved palette with it own color name

it would be very cool to use a pre-created palette (except RGB) from which the desired colors are selected, which corresponds to those available in stores .

For example - Gamma palette https://www.peredvizhnik.ru/upload/iblock/80b/akrilgamma.jpg
or Ladoga http://molberty.com.ua/userfiles/shop/large/3127_akrilovaya-kraska-ladoga-100m.jpg
it have 41 colors or less

we load this palette as color name and RGB equvalent in to your program
and program can choose color ( 4...41) frome this palette
as result is palette.png file (verical demention for usability read) must contain sample color +number+ color name frome custome palette

Issues building the CLI

$ pkg .

[email protected]
Targets not specified. Assuming:
node10-linux-x64, node10-macos-x64, node10-win-x64
Warning Cannot resolve 'configPath'
T:\0_eBookAmazon\paintbynumbersgenerator\src-cli\main.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
Error! TypeError: buf.readBigUInt64LE is not a function

Feedback and Suggestions for the Paint by Colour Image Generator

Hi Project Owner,

I recently tried out your paint by colour image generator, and I think it's a fantastic tool. It's impressive how it generates colored images accurately. However, I had an idea that I believe could make the tool even more versatile.

Currently, the tool provides images that are already colored, which is undoubtedly helpful for many users. However, I believe it could be beneficial to include an option to generate plain images (black and white or gray scale) as well. This would allow users to exercise their creativity and have the freedom to apply their preferred colors to the images.

By providing both colored and plain versions, your tool could cater to a broader audience, from those who seek convenience to those who want to personalise their creations. Additionally, it could serve as a valuable educational tool for artists and hobbyists who wish to practice their coloring skills.

I understand that this suggestion may require additional development, but I believe it could significantly enhance the user experience and make your tool even more valuable to the community.

Thank you for considering my suggestion, and I'm looking forward to seeing how your project evolves.

Best regards,
Patrici Bal

paintbynumbers
palette

Possible Malware

I ran the zip file through virustotal.com and got message:

"1 security vendor flagged this file as malicious"

MaxSecure Trojan.Malware.300983.susgen

Compiling CLI version

When I'm trying to compile CLI version, pkg returns a message below:
> Error! Bin file does not exist (taken from package.json 'bin' property) /var/www/public/paintbynumbersgenerator/src-cli/main.js

So I changed 'bin' property to "./src-cli/main.ts". Then I got a message
> Error! Unexpected token (19:11) /var/www/public/paintbynumbersgenerator/src-cli/main.ts

How could I compile a CLI version?

Invisible shapes

I currently played around a lot with your tool lately and I found something mysterious. I used some clipart pictures and sometimes - just sometimes your tool is making shapes hidden or so small that they are not even visible. (I truly added the variable of remove shapes smaller then...) I inspected the .svg image and found out that there are the shapes but "hidden" because they are very very small and in the left bottom corner. I also found a svg path with a height of zero?!

What to to to fix it and what causes this?

Link to example wrong image:
https://www.dropbox.com/s/rtalyw4twluvtcf/tabs-out.svg?dl=0&raw=1

Error! Bin file does not exist

Hi, when I use 'pkg.'.
But error:
Error! Bin file does not exist (taken from package.json 'bin' property)
D:\py_projects\paintbynumbersgenerator\src-cli\main.js
How to fix it?
Please help me, thanks a lot!

Offer to contribute: sort palette by color value

Hi @drake7707,

I would like to add the ability to sort the final palette by value, so that the darker values = higher numbers in the palette.

Might you allow me to contribute this option? If so, where in the code might I focus?

Wonderful work. Would love to make a donation, btw.

Logan

Export files

Hi, great programme, I love it! Not an issue really just wondering if it would be possible to enable export outputs in Jpeg and Pdf files as well?

smooth curves and thinkness

need function to smooth curves - all curves looks as polyline curves, but it not good to paint

cood you make function to define level of smoothing curves ?
cood you make function to define level of thinkness of the lines? hairline for example )

Issue with lab colors

Thanks for the software, it works pretty well.
There is an issue in options, when I choose "Clustering color space "= Lab
and add a few colors:
65,36,-18
76,34,7
73,-9,44

the software changes the negative values to 0.
In the palette, it says
65,36,0
76,34,7
73,0,44

"Protect" a color

Some colors are important for an image to the point of needing to be preserved as is and not averaged together with similar colors. For example, in the attached image the sand needs to stay yellowish rather than be turned into white.

On another note, @drake7707 please check your spambox for email from [email protected]

2020-08-25_20h03_39

Colorize labels

As the title suggests, an option to colorize the labels to match the required color (even if they are light or white colors) would be great

Problem with compiling package

  • In package.json there is a problem with binary file for pkg module
  • There is no target platform specified for pkg module

Vector import

It's possible to import a vector image?
For example to import svg file and only numbers ad colors numbers.

Useful when you design the file in AI. With the current build, you must export the file in png and to trace it again this leed to quality loss

Smooth the curves

I think you should make the curves smoother
It will be easier to paint in real life

And it's perfect if the user can define the smoothing level

Issues building the CLI

  1. In the image, that should be "ts", yes?
    image
  2. After changing to .ts:
    image

My little brain can't go past this without significant effort.

saving SVG fails in chrome

saving the SVG file in chrome fails with "network error".

the png and palette save seem to work fine.

SVG saving works fine in firefox, but not in edge or chrome.

ReferenceError: define is not defined

This Software is sooooo coool. Thank you so much for that!
I got it working on my macbook. And also I was able to get the CLI compiled. But when I try to run it I get the error message:

pkg/prelude/bootstrap.js:1320
return wrapper.apply(this.exports, args);
^

ReferenceError: define is not defined
at Object. (/snapshot/paintbynumbersgenerator-master/src-cli/main.js)
at Module._compile (pkg/prelude/bootstrap.js:1320:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1218:10)
at Module.load (internal/modules/cjs/loader.js:1047:32)
at Function.Module._load (internal/modules/cjs/loader.js:935:14)
at Function.Module.runMain (pkg/prelude/bootstrap.js:1375:12)
at internal/main/run_main_module.js:17:47

any Idea what I could do?

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.