I need to break down grayscale images into 4 shades of gray, but each shade should consist of horizontal black lines. So black would have a certain density of lines, shade 1 would have 25% less, shade 2 would have 50% less and white would have no lines at all. I would love if this could be done in vector.

An example on the attached picture below. enter image description here

The reason I need this is because I use laser and CNC and I can't find a way to engrave pictures with constant depth. All the solutions I've found map the shades to different depths so the cuts are deeper or shallower according to the shades.

Is there a way to do this?


  • Yeah its called halftoning. But yeah what you propose can also be done. See here. PS our lasers defaults to halftoning with constant depth so it does not need a tutorial as its the default state.
    – joojaa
    Commented Dec 24, 2020 at 23:35

2 Answers 2


Let's assume you have a photo that you want to convert to contain only a few greyshades - your question said black, white and 2 more greys between them. You must somehow decide how to divide the photo to different greyshade areas so that the image is still recognizable.

Desaturating and posterizing are not enough. You cannot generally adjust the posterizing tresholds and differently colored areas very likely need different tresholds. You could make color balance and curves adjustments before desaturating and posterizing, but that would be a long guess, undo and retry sequence. The next image has got auto-contrast, desaturating and posterizing to 4 levels. Dark end has lost most of the details:

enter image description here

Photoshop has adjustment layers which make the job manageable. One example:

enter image description here

The Black&White mixer layer is especially handy because it gives different weights to different colors. The curves layer has only a BW image to adjust, it's easy to find the curve which fits into the fixed tresholds of the posterizing layer.

I guess for best results one should make selections and paint some not so important areas with solid colors to fade unwanted small details. I skip it.

2 greys + black and white is very little to present real world photos. Inserting 2 greys more (=total six posterizing levels) gives more details and helps to keep clutter out of the background items:

enter image description here

More white on the face can be got by increasing the contrast with the curves but the background starts to get rubble:

enter image description here

Many of us use freeware (GIMP, Krita) which don't have Photoshop's functionality. GIMP doesn't have adjustment layers but it has fortunately very well working desaturating mono mixer. I succeeded to get good results also in GIMP by applying that mono mixer, curves and posterizing separately. It needed four full Undos and retries, but I knew already what to expect.

Krita has (without any extensions) adjustment masks which essentially do the same as adjustment layers, but need a couple of extra clicks. The next image is an attempt in Krita. There's no mono mixer, but as a workaround the curves adjustment mask is applied to RGB channels separately:

enter image description here

This is different than the Photoshop version. The posterization in Krita has logarithmic treshold series which make the adjustment logic totally different.

Converting the greyshades to different line densities is something which doesn't exist in common half-toning methods. Common line half-toning methods have constant line density, but vary line widths according the brightness.

You can do the conversion in a raster image program if you have an image with high enough resolution. The previous image is 1500 px high which allows max. 750 horizontal lines (=1 px wide line, 1 px space between lines). Do not think this is even more than in low spec video because to get different line densities for black, white and 4 greys you must proceed in 10 px high vertical zones. That gives only 150 effective lines and, as said, there's only 6 different brightness levels.

You can select the different greyshade areas one by one and fill them with the next 10 x 10 px Black&White patterns that you must prepare beforehand to be used as fill patterns:

enter image description here

In Photoshop you fill a selection by clicking the image once with a bigger than image Pattern Stamp. The areas can be selected with the magic wand (tolerance=0, non-contiguous, no anti-aliasing).

The posterized photo is flattened to the backgound layer, it's used to make the selections. The fills are made to separate layers for easy vectorizing if needed.

enter image description here

This looks messy because the lines interfere with the screen. With high zoom in one can see it's ok:

enter image description here

In GIMP pattern fills can be used in the same way. Patterns unfortunately must be prepared as separate files to GIMP's pattern folder. Search GIMP's documents or web tutorials how to make own patterns.

Making a vector:

The posterized and flattened image (this is the "more white on the face" version) seems to get traced well in Illustrator. Grayscale tracing, fills only, no strokes and ignoring white give 877 closed shapes which can be used to clip line clouds:

enter image description here

The smallest rubble vanishes because there's minimum area =20px and 3px path errors are allowed.

Expanding and Ungrouping the tracing result make the generated shapes accessible. There are 877 shapes.

One can combine the shapes with the same fill color by selecting one, then applying Select > Same > Fill Color and finally applying Object > Compound path > Make. Pathfinder Unite doesn't work because many of the shapes are already compound paths (=have holes).

Combining 5 times (not 6 because there's no white) the Layers panel start to look simple. In the next image all except blacks are made invisible:

enter image description here

You can in theory replace the fill colors by applying pattern fill swatches which are made by blending horizontal lines as the 2 days older answer suggests. It has a drawback. Pattern fills are based on clipping masks. I'm not at all sure if they are understood right when you want to make a file for a cutting machine. I have not such machines and the files I have made for others were all DXFs with no extras, 1:1 as the cutting was wanted.

It's well possible that some modern machines can understand say SVG exports or Ai files with clipping masks and repeated symbols, even curves as bitmap images, but I do not know those machines.

Let's check how clip a cloud of lines with our blacks without using clipping masks nor converting the lines to rectangles. In the next image a little bigger area than the image is filled with black horizontal lines. The black compound of the traced image is colored to green to make it better visible, it's color is meaningless.

enter image description here

The lines were made by blending the top and bottom line with 300 steps. The blend is expanded and Ungrouped. The traced compound of blacks must be on the top.

An easy way to continue would be to use the traced compound as a clipping mask, but I want to really remove the extras, not to make them only invisible.

If the traced image was simple one could sweep the extras off manually with the Shape Builder, but this is not an option with images this complex. But Patfinder Panel's Crop can be used. It needs some obscure preparations: Select the lines. Select one and the Select > Same > Stroke color (be sure that everything else with the same stroke color is locked). Combine the lines to compound path and apply a fill color. It becomes the stroke color.I apply red to show it:

enter image description here

Only the appearance panel tells the combined lines have red fill. It's invisible but it's needed and that's the obscure point.

Select the traced compound of blacks and the line compound. Click Crop in the Pathfinder Panel. A group is generated:

enter image description here

The group has the wanted parts of the lines as zero width red lines and fully colorless closed paths which together are the traced compound of blacks splintered to pieces.

Ungroup. Select one red line, select the same stroke color and give to all visible stroke width. Select all colorless splinters and delete them. You get all selected by finding one and selecting the same stroke color. Here's the result (still red, sorry!):

enter image description here

There's plenty of steps needed only for one greyshade. But all other traced greyshade compounds are there waiting and you can prepare the different line clouds easily from the same top and bottom lines, only copy and paste in place the whole blend to get a duplicate before expanding one. Change the spacing in the copy. Keep waiting line clouds locked.

Inkscape doesn't have anything which crops automatically lines or other open paths like Illustrator's Pathfinder. One can use tracing result as clipping path and make the unwanted parts of lines invisible in Inkscape, but they are still there. If one exports as DXF the lines are untouched in the resulted DXF.

A workaround is to convert the lines to rectangles (Path > Stroke to Path). Path > Intersect clips the converted lines - only combine the lines and combine also the pieces in the traced shape. Cropped lines unfortunately are closed paths and that can be untolerable for cutting jobs.

One possibility to remove automatically the invisible parts of clipped open lines is to rasterize in high resolution. Centerline tracing regenerates the visible parts of the lines. Do it separately for different grayshades to avoid obscure twisted paths.

The needed bitmap resolution and the high number of re-traced line segments make Inkscape slow. The needed resolution is much lower if the bitmap version of the cropped lines is pixel perfect. It can be got directly from Photoshop or GIMP as presented in the beginning. We try it next.

The multilayer bitmap image version of the lines (made by pattern fills) needs something that can be used to align the layers after they are pasted to Inkscape as separate images. An easy way is to expand the size of the canvas a little and paint to every layer a colored dot in the same corner. That makes every layer to start from the same point:

enter image description here

The layers are copied and pasted one by one to Inkscape. The pasting happens where the cursor happens to be, but the red dot makes every image to have something in the corner, so the bounding boxes at least snap perfectly together there.

Every image must be traced separately as Black and white. Tracing mode Centerline autotrace works perfectly. Every image generates one combined path. enter image description here

Remove or hide the pasted images and give to the paths a good stroke width to see the result:

enter image description here

This high zoom screenshot shows that the lines are not contiguous. That's because the lines are from different tracings and there were gaps in the bitmap image version. Unfortunately I do not know any practical way to join those line segments which could be joined without causing substantial change to the image.

Just for curiosity I deleted the bitmap images and saved as DXF (ver. AutoCAD R14). I didn't break apart the combined paths. A CAD program opened the DXF perfectly and every line segment was freely selectable and editable.

enter image description here

  • Wow, amazing breakdown. Thank you so much for taking the time for such an extensive and thorough answer. I really appreciate it! Can't thank you enough. I too base my workflow around OSS, so it's pretty much Gimp, Inkscape and Blender.
    – J.Nada
    Commented Dec 28, 2020 at 23:19

This is for Adobe Illustrator.

Without doing a full blown tutorial, here is how I would approach this:

Make a blend of black lines at the various densities you want (100%, 75%, 50%, etc.)

enter image description here

Expand each of those blends and make a pattern fill swatch for each of those (Object> Pattern> Make). You will probably have to adjust the width and height to get the pattern to repeat well.

If you make your 4 color grayscale (in vector) you can then select one filled area and go to Select> Same Fill Color- it will select all same filled objects and you can apply the pattern fill you made with one click.

  • I use Inkscape and Gimp but I got the idea and will try it. Awesome workaround, I would have never thought of it. Thank you very much!
    – J.Nada
    Commented Dec 26, 2020 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.