Papers
Topics
Authors
Recent
Search
2000 character limit reached

Image2Gcode: Direct G-code from Visual Input

Updated 3 July 2026
  • Image2Gcode is an additive manufacturing framework that directly converts 2D images into executable G-code, bypassing traditional CAD-to-slicer workflows.
  • It employs a conditional diffusion-transformer and a 1D U-Net to transform noisy keypoint sequences from slice images into precise print trajectories.
  • Empirical evaluations demonstrate 100% execution reliability, diverse infill strategies, and nearly identical travel distances compared to conventional methods.

Image2Gcode is an end-to-end data-driven framework for additive manufacturing that generates printer-ready G-code directly from images and part drawings, bypassing the conventional CAD-to-STL-to-slicer pipeline. In the reported formulation, a hand-drawn or captured 2D image serves as the sole input; the system extracts slice-wise structural cues from that image and applies a denoising diffusion probabilistic model over G-code sequences to produce executable print-move trajectories with associated extrusion parameters. By operating directly on native toolpaths rather than on an explicit 3D model, the framework is positioned as a direct mapping from visual input to material-extrusion (MEX) printer instructions (Wang et al., 25 Nov 2025).

1. Workflow position and problem formulation

Conventional mechanical design and manufacturing workflows begin with conceptual design, followed by construction of a computer-aided design model and fabrication through MEX printing. In that workflow, CAD geometry must be converted into machine-readable G-code through slicing and path planning. Image2Gcode is introduced to remove the CAD stage as a bottleneck, particularly in rapid prototyping contexts where even minor design variations require manual updates in CAD software and make iterative design slow to scale (Wang et al., 25 Nov 2025).

The framework takes two principal forms of visual input. The first is 2D slice images rendered from STL meshes as 224×224224 \times 224 grayscale images. The second is real-world photographs or hand-drawn sketches that are preprocessed into binary silhouettes. Its output is printer-ready G-code sequences expressed as G1 X… Y… E… commands together with initialization and shutdown commands.

The pipeline consists of three high-level stages: preprocessing, a generative model, and post-processing. Preprocessing extracts per-layer images and aligned toolpath keypoints. The generative component is a diffusion-transformer that maps noisy keypoint sequences conditioned on slice features. Post-processing denormalizes predictions, formats them into G-code, and applies basic validity checks. This organization suggests that Image2Gcode treats toolpath generation as a conditional structured-sequence synthesis problem rather than as explicit geometric reconstruction.

2. Preprocessing, slicing alignment, and tokenization

Training data are derived from the Slice-100K dataset, described as approximately 100 000100\,000 STL–G-code examples. For each STL and G-code pair, the system performs layer-level alignment. It detects ZZ-height changes in G-code from G1 commands, slices the STL mesh at the same ZZ using PyVista to obtain a grayscale image, and extracts the toolpath as a sequence of NN points

X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}

from cumulative-extrusion G1 commands (Wang et al., 25 Nov 2025).

Normalization is channel-specific. Spatial channels XX and YY are centered by the bounding-box midpoint and scaled so that the maximum dimension maps to [−1,1][-1,1]. The extrusion channel EE is min–max normalized per layer to 100 000100\,0000. Because sequence lengths vary across layers, each sequence is padded or truncated to a fixed length 100 000100\,0001, and a binary mask

100 000100\,0002

is stored to indicate valid positions.

Each keypoint 100 000100\,0003 is treated as a token for the diffusion model. No explicit positional encoding is applied to these tokens; ordering is instead captured through 1D convolutions and self-attention. This design places the sequential structure of print moves inside the denoising backbone rather than in an external geometric graph or symbolic planner.

3. Conditional diffusion-transformer architecture

The vision-conditioning backbone is DinoV2-Small, a Vision Transformer with 100 000100\,0004 patches, embedding dimension 100 000100\,0005, and 100 000100\,0006 layers, producing 100 000100\,0007 patch tokens. The encoder is pretrained on 100 000100\,0008 M images, and all but the last two layers are frozen during fine-tuning. The resulting multi-scale slice features 100 000100\,0009 are supplied to the generative model through cross-attention (Wang et al., 25 Nov 2025).

The denoising process is defined over keypoint sequences. With ZZ0 timesteps, the forward diffusion process is

ZZ1

where

ZZ2

follows a cosine schedule. The model uses ZZ3-prediction, meaning that it predicts the clean sequence ZZ4 directly from the noisy sequence ZZ5. Reverse transitions are implemented implicitly by iterative denoising.

The denoising backbone is a 1D U-Net. The input sequence ZZ6 is projected to ZZ7 dimensions via a ZZ8 convolution. The network uses five scales with channel multipliers ZZ9. Each stage contains residual blocks with GroupNorm and SiLU, together with strided-convolution downsampling, linear upsampling, and skip connections. Timestep ZZ0 is embedded via sinusoidal encoding and passed through a small MLP before being injected into each block through FiLM-style affine modulation.

Cross-attention is applied at multiple U-Net depths. Keypoint features ZZ1 attend over Dino tokens ZZ2, with ZZ3, according to

ZZ4

where the head dimension is ZZ5. The number of attention heads increases in deeper layers for efficiency. A plausible implication is that the architecture uses early visual features for coarse boundary conditioning and deeper sequence representations for more structured toolpath refinement, although the paper states only the placement of cross-attention and not an explicit functional decomposition.

4. Objective, optimization, and implementation choices

The training objective is a masked diffusion loss over valid sequence positions: ZZ6 The mask ZZ7 excludes padded positions. Channel weights are ZZ8 for ZZ9, NN0, and NN1, respectively, and SNR-based timestep weighting is applied (Wang et al., 25 Nov 2025).

Training uses Slice-100K with a NN2 train/validation split on slice-level examples. Only synthetic data are used during training; real photographs and sketches are reserved for zero-shot generalization tests. No additional geometric augmentations are reported.

The implementation is in PyTorch with multi-GPU training. The batch size is NN3 per GPU, and training runs for NN4 epochs. Optimization uses AdamW with learning rate NN5 and weight decay NN6. The learning-rate scheduler is ReduceLROnPlateau with factor NN7, patience NN8, and minimum NN9. Gradient clipping is enabled, while mixed precision and checkpointing are disabled.

Several architectural and hyperparameter choices were selected through reported ablation. The U-Net channel multipliers X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}0 were chosen via early search, X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}1 was selected as a trade-off between quality and compute, and partial fine-tuning of only the top two DinoV2 layers was found to stabilize training while preserving pre-learned geometric features. The input resolution was fixed at X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}2, with higher resolutions showing diminishing returns relative to compute cost.

5. Sampling, denormalization, and G-code synthesis

At inference time, sampling begins from

X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}3

followed by iterative denoising for X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}4. The model produces

X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}5

together with mask X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}6 (Wang et al., 25 Nov 2025).

Denormalization reverses the preprocessing transformations. For spatial channels, X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}7 and X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}8 are restored using cached bounding-box dimensions and midpoint. For extrusion, X0={(Xi,Yi,Ei)}i=1NX_0 = \{(X_i, Y_i, E_i)\}_{i=1}^{N}9 is restored using the per-layer min–max statistics and then multiplied by a printer-specific extrusion multiplier.

G-code formatting is explicit. The generated file prepends G90, M82, temperature commands, and homing. For each valid keypoint XX0, the framework writes XX9 and appends standard retraction and motor-off commands. Basic validity checks are then applied: coordinates must remain within build-volume limits, and the XX1 channel must increase monotonically. No further geometric repair heuristics are reported.

This post-processing stage is significant because it distinguishes Image2Gcode from systems that stop at geometric prediction. The output is intended to be directly executable by a printer, subject only to the stated formatting and validity constraints.

6. Empirical behavior, generalization, and measured outcomes

The reported qualitative outcome is that generated perimeters accurately follow boundaries and that infill patterns, including hatching, honeycomb, and concentric structures, emerge without rule-based slicing. Physical prints are described as exhibiting good dimensional accuracy and surface quality (Wang et al., 25 Nov 2025).

Generalization is evaluated in a zero-shot setting on photographs and hand sketches after simple edge-based silhouette extraction. The reported behavior is that toolpaths remain coherent and prints succeed across non-polygonal shapes. The paper also reports novel infill diversity: the model can generate multiple valid infill strategies for the same boundary, such as rectilinear versus concentric patterns. This is presented as evidence that the model learns a distribution over feasible toolpaths rather than memorizing a single heuristic mapping.

A quantitative comparison is reported using travel distance, defined as total nozzle motion length per layer. A kernel density estimate yields a mean generated travel distance of XX2 units versus heuristic ground-truth at XX3 units, corresponding to an approximately XX4 reduction. The XX5 bootstrap confidence interval is reported as narrow, indicating consistency across runs.

Execution reliability is reported as XX6 on held-out slices and real-world inputs. The generated paths are described as comparable to or better than those from a standard CAD-to-slicer pipeline in path efficiency. Because the reported comparisons are centered on execution success and travel distance, a plausible implication is that the principal empirical contribution lies in functional toolpath synthesis rather than in exhaustive benchmarking against full slicer ecosystems.

7. Constraints, failure modes, and research directions

The stated limitations are tightly coupled to the slice-by-slice design. Because the method lacks explicit cross-layer coordination, it cannot handle drastic topology changes between layers. Fine features below XX7 mm are occasionally blurred, and corner sharpness is slightly rounded. Dataset diversity is also limited to heuristically sliced patterns, leaving gaps in coverage for exotic infill strategies (Wang et al., 25 Nov 2025).

Scalability limitations are also identified. Using XX8 denoising steps incurs inference latency on the order of seconds per layer. Increasing the size of the ViT backbone or raising image resolution would increase memory and compute demand.

Several future directions are proposed. One is a hierarchical 3D pipeline that first generates a small set of key cross-sections and then applies the slice-toolpath model per layer. Another is to introduce explicit conditioning variables such as infill density, pattern type, mechanical performance targets, or natural-language instructions via an LLM embedding. Additional directions include replacing the 1D U-Net with more efficient diffusion architectures such as DDIM or latent diffusion to reduce sampling steps, integrating multi-view or depth cues for full volumetric conditioning, and jointly learning slicing parameters such as layer height and shell count alongside toolpath generation.

These limitations clarify a common misconception that bypassing CAD necessarily yields full geometric autonomy. In the reported system, CAD and STL intermediates are removed from the deployment path, but the learned representation remains layer-conditioned and depends on training data derived from paired STL and G-code examples. The framework therefore redefines where geometric prior knowledge enters the pipeline rather than eliminating such priors altogether.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Image2Gcode.