458 words
2 minutes
Real ASCII - Contour Shade Filter

This filter renders shading around the edges in the given image. Like shade filter, a palette is required. (Might also require more manual finetuning than the shade filter)

📖 Guide: Contour Shade ASCII Art#

1️⃣ cd to src/contour_shade.

2️⃣ Set up a palette. Recommended save directory is resource/palette_files. Check out the palette tutorial.

3️⃣ Execute contour_shade.py. Example:

Terminal window
python contour_shade.py --image_path ../../resource/imgs/tsunami.jpg --resize_factor 4 --contrast_factor 16 --resize_method bilinear --thresholds_gamma 1.2

Parameters

argumenthelp
—image_pathThe path of the image.
—save_pathThe directory where the result image will be saved to.
—resize_methodThe image resize method. Check below for available options.
—resize_factorThe resize factor of the new image.
—contrast_factorThe contrast factor based on the original image.
—sigma_sThe value of color smoothing in area.
—sigma_rThe value of color smoothing in edges.
—thresholds_gammaControls the shading (gradient) levels. Higher value makes the algorithm emphasis the bright pixels. (Better granularity)
—palette_pathUse a palette.
—max_workersThe maximum number of multithread workers.
—invert_colorIf included, invert the color of the result image.
—sigmaXThe standard deviation of GaussianBlur kernel in the horizontal direction.
—ksizeThe kernel size of contour function.
—gxThe image gradient in the horizontal edges.
—gyThe image gradient in the vertical edges.
—color_optionThe option to color the image. Check below for available options.
—save_asciiIf included, the characters will be saved to a file.
—save_ascii_pathThe path to save the characters. Check out the ‘ascii_output’ folder for the results.
—antialiasingIf included, retain anti-aliasing of the characters.
—reference_numOnly used if the palette file is non-fixed width. Takes previous character as reference to replace ‘filler’ characters. A filler is a 1px * the row height empty character used to filling in the gaps that cannot be matched with the given characters in palette.
—max_num_fill_itemOnly used if the palette file is non-fixed width. This value is the maximum number of characters used to fill any gap.
—filler_lambdaOnly used if the palette file is non-fixed width. Larger lambda indicates more emphasis on the gap filling with palette characters and less emphasis on the similarity between filling choices and the references.
—char_weight_sum_factorOnly used if the palette file is non-fixed width. This factor indicates the importance of character weights when deciding the next character.
—curr_layer_weight_factorOnly used if the palette file is non-fixed width. This factor indicates the importance of a particular layer when deciding the next character. By default, we assume that the gradient image in higher index have more importance.
—offset_mse_factorOnly used if the palette file is non-fixed width. This factor indicates the importance of mean squared error when deciding the next character. Higher MSE means less likely to be chosen.
—coherence_score_factorOnly used if the palette file is non-fixed width. This factor indicates the importance of staying in the same level when deciding the next character.

resize_method

codehelp
nearest neighborResize image with nearest neighbor algorithm.
bilinearResize image with bilinear algorithm.

color_option

codehelp
originalColor the ASCII art with the (resized) original image’s color.

An example of ascii art image:


🖼️ Also check out the gallery for more examples!


⭐ Image Credit: tsunami (Wikipedia)

Real ASCII - Contour Shade Filter
https://marblestack.github.io/marblestack/posts/b_ascii/g_contour_shade/
Author
MarbleStack
Published at
2025-12-21
License
CC BY-NC-SA 4.0