426 words
2 minutes
Real ASCII - Depth Shade Filter

The shade filter renders the image with shading. Unlike in the trace filter, where palette is optional, shade filter requires you to set up a palette.

📖 Guide: Depth Shade ASCII Art#

1️⃣ cd to src/depth_shade.

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

3️⃣ Execute depth_shade.py. Example:

Terminal window
python depth_shade.py --image_path ../../resource/imgs/monalisa.jpg --resize_factor 4 --invert_color

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.
—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 (compressed):


🖼️ Also check out the gallery for more examples!


⭐ Image Credit: monalisa (Wikipedia)

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