Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
94166af
Maven: extend project file
hoijui Mar 17, 2018
695e7bf
fix lots of CheckStyle reported issues
hoijui Mar 17, 2018
eec0f28
fix many PMD reported issues
hoijui Mar 17, 2018
1d76cea
fix two FindBugs reported issues
hoijui Mar 17, 2018
a6d3772
rename GrayscaleMatrix -> GrayScaleMatrix
hoijui Mar 17, 2018
0022a02
cleanup test sources
hoijui Mar 17, 2018
955dfb1
fix some JavaDoc issues
hoijui Mar 17, 2018
5fced5e
remove redundant casts
hoijui Mar 17, 2018
7c848b0
use more modern Java syntax
hoijui Mar 17, 2018
d11fe6c
mark some fields and one method `final`
hoijui Mar 17, 2018
841824d
suppress overflow warning, as it is intended behaviour
hoijui Mar 17, 2018
cec9dc0
white-space cleanup in test sources
hoijui Mar 17, 2018
1cb07b6
rename TiledGrayscaleMatrix -> TiledGrayScaleMatrix & fix many other …
hoijui Mar 18, 2018
7ba6aa2
fix indenting
hoijui Mar 18, 2018
41864eb
do not hide fields
hoijui Mar 18, 2018
772e8c4
minor white-space fix
hoijui Mar 18, 2018
6e64019
move example images to test resources
hoijui Mar 18, 2018
95f664e
README: markdown syntax fixes and minor cleanup here and there
hoijui Mar 18, 2018
625b8c9
ascii -> ASCII (in comments)
hoijui Mar 18, 2018
15d0e22
fix typo in method name
hoijui Mar 18, 2018
caffe62
GifToAsciiConvert: white-space and doc fixes
hoijui Mar 18, 2018
a9b330b
StringBuffer -> StringBuilder (& minor cleanup)
hoijui Mar 18, 2018
53fe1ed
huge refactor
hoijui Mar 18, 2018
07a30fe
rename package character_fit_strategy to strategy
hoijui Mar 18, 2018
f1f4700
minor matrix package cleanup
hoijui Mar 18, 2018
9086bd7
move test classes to the same package as the classes they are testing
hoijui Mar 18, 2018
72d569c
mini docu fixes [minor]
hoijui Jun 2, 2018
cd27942
slightly more verbose image convert code
hoijui Jun 2, 2018
6f64c11
correct a comment typo [minor]
hoijui Jun 2, 2018
d0c2a48
rename "finalize" to "imageEnd"
hoijui Jun 2, 2018
913569a
make a helper method static
hoijui Jun 2, 2018
2e76985
extend `AsciiExporter#init` arguments
hoijui Jun 2, 2018
87fd36d
GrayScaleMatrix: use more natural interface for data
hoijui Jun 2, 2018
e987f19
GrayScaleMatrix: use more natural data storage
hoijui Jun 2, 2018
bbdd536
use proper interface & impl. naming for CharacterFitStrategy
hoijui Jun 2, 2018
24226cd
fix a lot of JavaDoc comments
hoijui Jun 2, 2018
189c19b
remove some code duplication
hoijui Jun 2, 2018
baa98ad
rename GifToAsciiConvert -> GifToAsciiConverter
hoijui Jun 3, 2018
50c7bb2
implement static code analysis cleanup suggestions
hoijui Jun 3, 2018
3761978
minor cleanup
hoijui Jun 24, 2018
a711d21
use state-fullness of AsciiExporter to store sourceImagePixels & imag…
hoijui Sep 8, 2018
62ae74e
*Exporter comment fixes [minor]
hoijui Sep 8, 2018
09a3a30
formatting fix [nlc]
hoijui Sep 8, 2018
83b2630
correct package for test classes [fix]
hoijui Sep 8, 2018
06eee10
refactor
hoijui Sep 8, 2018
77b0744
simplify & speedup image export (removing double buffering)
hoijui Sep 9, 2018
1a2053a
remove unused import [nlc]
hoijui Sep 9, 2018
cf8b1cc
factor out CharacterFinder "algorithm"
hoijui Sep 9, 2018
ea164af
decouple importing (somewhat)
hoijui Sep 9, 2018
0878285
formatting fix [minor]
hoijui Sep 9, 2018
586e5fc
make `TiledImageMatrix` iterable
hoijui Sep 9, 2018
1c10850
AbstractToAsciiConverter: sanitize order of methods [nlc]
hoijui Sep 9, 2018
785d002
separate out importing/reading from the converter
hoijui Sep 10, 2018
46adb62
make all exporters support multiple frames
hoijui Sep 10, 2018
53515a4
update and extend GIF test, including (crude) output validation
hoijui Sep 10, 2018
20699bd
update normal image test file names
hoijui Sep 10, 2018
9402897
use proper temporary files [test]
hoijui Sep 11, 2018
e62de4f
improve method names [test] [nlc]
hoijui Sep 11, 2018
cd1678c
make some static vars private [test]
hoijui Sep 11, 2018
b596b6b
minor improvement of textual export [test]
hoijui Sep 11, 2018
9b3894d
rename suffix variable [nlc] [test]
hoijui Sep 11, 2018
ec7f616
implement verification of textual output [test]
hoijui Sep 11, 2018
e561be6
add more textual output tests [test]
hoijui Sep 11, 2018
73b4deb
fix JavaDoc issues [nlc]
hoijui Sep 12, 2018
4db87e7
refactor some things; including decoupling output from input
hoijui Sep 12, 2018
2651730
fix some CheckStyle and PMD reported issues
hoijui Sep 12, 2018
224e283
add MIT license boilerplate headers to java source files [minor]
hoijui Sep 12, 2018
87c9fb4
fix base package name [maven]
hoijui Sep 12, 2018
cc9b02f
unuse * imports [nlc]
hoijui Sep 12, 2018
e56ef51
CheckStyle: LeftCurly.option = "nlow"
hoijui Sep 12, 2018
f9762ce
fix Leftcurly braces [nlc]
hoijui Sep 12, 2018
8ed4179
CheckStyle: check for MIT license boilerplate source file header
hoijui Sep 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 50 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,73 @@
asciimg
========
# asciimg

Asciimg is an extensible Ascii art generator written in Java.
For more info refer to this blog post:
<a href="http://korhner.github.io/java/image-processing/ascii-art-generator-part-2/">
http://korhner.github.io/java/image-processing/ascii-art-generator-part-2/</a>
Asciimg is an extensible ASCII art generator written in Java.
For more info refer to [this blog post](http://korhner.github.io/java/image-processing/ascii-art-generator-part-2/)

## Example usage

<pre>
// initialize cache
AsciiImgCache cache = AsciiImgCache.create(new Font("Courier",Font.BOLD, 6));
// initialize cache
AsciiImgCache cache = AsciiImgCache.create(new Font("Courier", Font.BOLD, 6));

// load image
BufferedImage portraitImage = ImageIO.read(new File("image.png"));
// load image
BufferedImage portraitImage = ImageIO.read(new File("input_image.png"));

// initialize converters
AsciiToImageConverter imageConverter =
new AsciiToImageConverter(cache, new ColorSquareErrorFitStrategy());
AsciiToStringConverter stringConverter =
new AsciiToStringConverter(cache, new StructuralSimilarityFitStrategy());
// initialize converters
AsciiToImageConverter imageConverter =
new AsciiToImageConverter(cache, new ColorSquareErrorFitStrategy());
AsciiToStringConverter stringConverter =
new AsciiToStringConverter(cache, new StructuralSimilarityFitStrategy());

// image output
ImageIO.write(imageConverter.convertImage(portraitImage), "png",
new File("ascii_art.png"));
// string converter, output to console
System.out.println(stringConverter.convertImage(portraitImage));
</pre>
// image output
ImageIO.write(imageConverter.convertImage(portraitImage), "png",
new File("ascii_art.png"));
// string converter, output to console
System.out.println(stringConverter.convertImage(portraitImage));

## Example output

Here are some sample images generated with various parameters:

<a href="http://korhner.github.io//assets/img/asciimg/orig.png">Original picture</a>
![Original picture](http://korhner.github.io//assets/img/asciimg/orig.png "Original picture")

<a href="http://korhner.github.io/assets/img/asciimg/large_square_error.png">16 pts font, MSE</a>
<a href="http://korhner.github.io/assets/img/asciimg/large_ssim.png">16 pts font, SSIM</a>
<a href="http://korhner.github.io/assets/img/asciimg/medium_square_error.png">10 pts font with 3 characters, MSE</a>
<a href="http://korhner.github.io/assets/img/asciimg/medium_ssim.png">10 pts font with 3 characters, SSIM</a>
<a href="http://korhner.github.io/assets/img/asciimg/small_square_error.png">6 pts font, MSE</a>
<a href="http://korhner.github.io/assets/img/asciimg/small_ssim.png">6 pts font, SSIM</a>
---------------------------------------

## Architecture:
![16 pts font, MSE](http://korhner.github.io/assets/img/asciimg/large_square_error.png "16 pts font, MSE")

- - -

![16 pts font, SSIM](http://korhner.github.io/assets/img/asciimg/large_ssim.png "16 pts font, SSIM")

- - -

![10 pts font with 3 characters, MSE](http://korhner.github.io/assets/img/asciimg/medium_square_error.png "10 pts font with 3 characters, MSE")

- - -

![10 pts font with 3 characters, SSIM](http://korhner.github.io/assets/img/asciimg/medium_ssim.png "10 pts font with 3 characters, SSIM")

- - -

![6 pts font, MSE](http://korhner.github.io/assets/img/asciimg/small_square_error.png "6 pts font, MSE")

- - -

![6 pts font, SSIM](http://korhner.github.io/assets/img/asciimg/small_ssim.png "6 pts font, SSIM")

## Architecture

![Architecture](http://korhner.github.io/assets/img/asciimg/asciimg_cls_diagram.png)

## AsciiImgCache

Before any ascii art rendering takes place, it is necessary to create an instance of this class.
Before any ASCII art rendering takes place, it is necessary to create an instance of this class.
It takes a font and a list of characters to use as parameters and it creates a map of images for every character.
There is also a default list of characters if you don't want to bother comming up with your own.
There is also a default list of characters if you don't want to bother comming up with your own.

### BestCharacterFitStrategy

This is the abstraction of the algorithm used for determining how similar a part of the source image with each character is.
The implementation should compare two images and return a float error. Each character will be compared and the one that returns the lowest error will be selected.
Currently there two implementations available: ColorSquareErrorFitStrategy and StructuralSimilarityFitStrategy.
This is the abstraction of the algorithm used for determining how similar a part of the source image with each character is.
The implementation should compare two images and return a float error. Each character will be compared and the one that returns the lowest error will be selected.
Currently there two implementations available: `ColorSquareErrorFitStrategy` and `StructuralSimilarityFitStrategy`.

#### ColorSquareErrorFitStrategy

Expand All @@ -64,13 +76,12 @@ Very simple to understand, it compares every pixel and calculates Mean squared e
#### StructuralSimilarityFitStrategy

The structural similarity (SSIM) index algorithm claims to reproduce human perception and its aim is to improve on traditional methods like MSE.
Uou can read more on <a href="http://en.wikipedia.org/wiki/Structural_similarity">Wikipedia</a> if you want to know more.
You can read more on [Wikipedia](http://en.wikipedia.org/wiki/Structural_similarity) if you want to know more.
I experimented a bit with it and implemented a version that seemed to produce the best results for this case.

### AsciiConverter<T>

This is the hearth of the process and it contains all the logic for tiling source image and utilizing concrete implementations for calculating character best fit.
However, it doesn't know how to create the concrete ascii art - it needs to be subclassed.
There are two implementations currently: AsciiToImageConverter and AsciiToStringConverter - which as you probably guessed, produce image and string output.

However, it doesn't know how to create the concrete ASCII art - it needs to be subclassed.
There are currently two implementations: `AsciiToImageConverter` and `AsciiToStringConverter` - which, as you probably guessed, produce image and string output.

Binary file removed examples/test-ascii.gif
Binary file not shown.
Loading