This program is my implementation of this simple image processing algorithm:
- load an image (source image)
- get a list of all the colors in the source image
- create 2 blank images (image1 and image2)
- draw a random polygon or circle on image1 using a random color from source image
- compare image1 to the source image
- if it's closer in color to the source image than image2, copy image1 to image2; if not, copy image2 to image1 and continue drawing more random shapes and comparing
- post the results and bits of code
Only requirements are SFML2.4 and the MingW C++ compiler on Windows and EasyBMP which is included with the source.
Build the executable in Visual Studio Code by following these instructions -
- In
c_cpp_properties.json
, depending on your platform ("name"), change theincludePath
andbrowse.path
json lists to include paths to both your C++ compiler and SFML headers - Update
tasks.json
with your standard C++ compiler build command. For example, mine is:
g++ src/main.cpp src/cfEngine.cpp src/easybmp/EasyBMP.o -I"D:/Code/C++/lib/SFML-2.4.2/include" -L"D:/Code/C++/lib/SFML-2.4.2/lib" -lsfml-graphics -lsfml-window -lsfml-system -std=c++17 -g -o chaiFilter
This will allow you to press Ctrl+Shift+B in your Visual Studio Code editor to automatically build your executable in your directory.
Download this repo and extract it somewhere. Run install.bat.
Keep the desired input images in the images
folder and then execute chaiFilter on your favorite commandline.
Currently only supports windows and tested on Powershell and command prompt.
To execute:
- Powershell -
./chaifilter ...
- Command Prompt -
chaifilter.exe ...
-
-h
The help command. Use this to display all the options in your command line.
-
Full Image Name
example: inputpic.jpg
-
-t GraphicType arg1
line
- arg1:integer - Maximum line length
circle
- arg1:integer - Maximum circle radius
blank arguments will cause errors use
-t
twice with both line and circle parameters for a mix of circles and linesexamples:
-t line 50
,-t rect 100 40
-
-m lineToCircle outlineToFill
Used to control level of mixing between lines and circles and circle outlines and filled circles.Number between 0-100 controlling amount of lines. >setting this to 100 will produce only lines
Number between 0-100 controlling amount of outlined circles. >lower value yields more filled circles
-
-f
Use filled shapes.
-
-i numberOfIterations
Omit in
visual mode
for an infinite render loop -
-v
Flag for
visual mode
or continuous rendering of the algorithm output onto a window.Warning: takes a long time
-
-d distanceFunction
* `euclideanDistance` * `taxiCabDistance`
Defaults to euclidean distance.
-
-AABB
Flag for using an AABB box to compare pixels instead of per-pixel. ** Not recommended. **
-
-k.. numberOfClusters
Use this option to do the chaiFilter algorithm with only numberOfClusters most important colors instead of all unique colors. This is implemented in the standard way - kmeans clustering.
k
: do kmeans with k=numberOfClustersk+
: do kmeans with k=numberOfClusters and initialize with kmeans++kv
: do kmeans with k=numberOfClusters and render in windowkv+
/k+v
: do kmeans with k=numberOfClusters and render in window with kmeans++ algo for initialization
-
-w
Flag for outputting the result as a bmp file in outputs/
.
-p
Flag for showing time taken by different functions in cfEngine. Simple profiler.
Not implemented yet.
You may have noticed that the output bmp file names detail the specific parameters of the algorithm used. It should be fairly easy to interpret, however, to make things clear:
- df - distance function
- iter - number of iterations
- line(n) - lines with max line length of n
- circle(n) - circles with max radius of n
- mixed(x,y) - mix of lines and circles with line to circle ratio set to x and outlined circle to filled circle ratio set to y
- k=n - kmeans clustering algorithm used with n clusters
- k++=n - kmeans clustering used with kmeans++ for initialization step and n clusters