Manuscript Offprint

arXiv:2609.02004

InstEditSeg: Instruction-Driven Image Editing for Polyp and Skin Lesion Segmentation

Ziquan Liu, Zhewei Zhu, Xuyang Shi

Ziquan Liu ID^{ID}, Zhewei Zhu ID^{ID}, and Xuyang Shi ✉^{✉}

School of Information and Control Engineering, Southwest University of Science and Technology, Mianyang 621010, China

{ziquanliu, zhuzw}@mails.swust.edu.cn, xuyangshi@swust.edu.cn

Abstract. Accurate segmentation of polyps and skin lesions is pivotal for clinical diagnosis, yet existing methods struggle with low contrast, ambiguous boundaries, and cross-domain distribution discrepancies. Discriminative networks and most diffusion-based segmentation approaches predict standalone binary masks, leaving the visual priors of large-scale pretrained generative models largely unexploited. We propose InstEditSeg, a unified generative framework that reformulates medical segmentation as an instruction-driven image editing problem. Instead of emitting a mask, the model renders a color-coded overlay on the original image, conditioned on a textual instruction, so that the edited output aligns with the natural image distribution learned by latent diffusion models and mitigates the domain gap between natural and medical imagery. To recover fine anatomical structures, we introduce DINOv3 as an auxiliary visual encoder and a DINO Feature Guidance Block that builds a multi-scale feature pyramid. The pyramid is fused into the diffusion U-Net by channel concatenation and zero-initialized convolution so that hierarchical discriminative priors can be injected without perturbing the pretrained weights. A dual-branch classifier-free guidance strategy requiring only two forward passes per denoising step reduces inference cost. On polyp and skin lesion benchmarks the framework achieves accuracy competitive with strong discriminative baselines, and it further demonstrates concrete advantages of the generative formulation: notably better cross-domain generalization on unseen data, more complete multi-lesion segmentation, instruction-conditioned task control, and sampling flexibility. We also analyze the strengths and limitations of the paradigm, including its color sensitivity and unsupported attribute-conditioned selection. Code is available at: https://github.com/wincharm001/InstEditSeg

1 Introduction

Colorectal cancer (CRC) is a leading cause of cancer-related mortality worldwide, and most cases originate from adenomatous polyps. Accurate polyp segmentation during colonoscopy is therefore crucial for early diagnosis, but it remains challenging due to low contrast, ambiguous boundaries, diverse morphology, and imaging artifacts such as uneven illumination and specular reflections, which hinder both accuracy and generalization.

Similarly, accurate segmentation of skin lesions in dermoscopic images is essential for the early diagnosis of melanoma [1][1], yet it faces comparable challenges, including fuzzy lesion borders, low contrast, and high inter-patient variability.

Deep learning has improved medical segmentation substantially. U-Net [2] became the de facto standard, while foundation models such as the Segment Anything Model (SAM) [3] show strong zero-shot capabilities. Nevertheless, SAM is trained on natural images and suffers substantial domain gaps on medical data, especially for small lesions and blurry boundaries.

Diffusion probabilistic models [4] offer an alternative paradigm. SegDiff [5] casts segmentation as iterative denoising, and MedSegDiff and MedSegDiff-V2 [6, 7] extend this to medical tasks. These approaches benefit from generative capabilities but still predict task-specific binary masks, making them specialized diffusion models rather than a unified generative framework.

Instruction-driven image editing [8] and unified visual generation models [9,10] show that detection, segmentation, and depth can be formulated as conditional generation. Using textual instructions, these models unify tasks within a single diffusion network and can produce color-coded segmentation directly, bridging visual understanding and generation. Applying them to medical images, however, faces two limitations: the substantial distribution gap between natural and medical images, and the limited spatial guidance of text alone for fine anatomical structures.

Figure

Fig. 1. Conceptual illustration of the proposed framework. Traditional methods generate binary masks. Our method reformulates segmentation as an image editing task. It renders color-coded regions on the original image to align with generative priors and mitigate domain shift.

We propose InstEditSeg, a unified generative framework that reformulates segmentation as instruction-driven image editing, producing an edited image that keeps the original content and adds color-coded regions; this aligns the output with the natural image prior of latent diffusion models and reduces the mismatch with medical images (Fig. 1). To compensate for the limited spatial guidance of denoising alone, we introduce DINOv3 as an auxiliary visual encoder and inject hierarchical features from a multi-scale pyramid into the U-Net, providing discriminative priors from local boundaries to global structure.

The editing formulation provides three advantages over discriminative baselines. The color-coded overlay keeps the original image content and aligns with the generative prior, so the model generalizes better to unseen settings, attaining the best Dice on the unseen PolypGen and ISIC2017 sets. The generative formulation also lets the model retain low-contrast secondary lesions that discriminative decoders drop, and a single architecture conditioned only on a text instruction covers multiple categories without task-specific heads or manual prompting. In-domain, the strongest discriminative baselines remain competitive, so the advantage is concentrated in generalization, segmentation completeness, and task control.

The main contributions of this work are summarized as follows:

– We propose InstEditSeg, a unified generative framework that recasts medical image segmentation as instruction-driven color-coded image editing, eliminating task-specific heads and aligning the output with latent diffusion priors.

– We develop an instruction-based data pipeline that converts segmentation annotations into unified image-text samples via textual instructions and randomized colors.

– We design a DINOv3-guided multi-scale feature pyramid that injects hierarchical discriminative priors into the diffusion U-Net, improving lesion localization and boundary delineation.

– Experiments on polyp and skin lesion benchmarks show competitive accuracy, notably better cross-domain generalization on unseen data, and concrete advantages of the editing formulation in multi-lesion completeness and instruction-conditioned task control.

References (45)

  • Skin lesion analysis toward melanoma detection: A challenge at the international symposium on biomedical imaging (isbi) 2016, hosted by the international skin imaging collaboration (isic)
  • U-net: Convolutional networks for biomedical image segmentation
  • Segment anything
  • Denoising diffusion probabilistic models
  • Segdiff: Image segmentation with diffusion probabilistic models
  • Medsegdiff: Medical image segmentation with diffusion probabilistic model
  • Medsegdiff-v2: Diffusion-based medical image segmentation with transformer
  • Instructpix2pix: Learning to follow image editing instructions
  • Image generators are generalist vision learners
  • Vision as unified multimodal generation
  • Attention u-net: Learning where to look for the pancreas
  • Unet++: A nested u-net architecture for medical image segmentation
  • Resunet++: An advanced architecture for medical image segmentation
  • Automated polyp segmentation in colonoscopy images using deep learning
  • Polyp-pvt: Polyp segmentation with pyramid vision transformers
  • Emcad: Efficient multi-scale convolutional attention decoding for medical image segmentation
  • Segment anything in medical images
  • Medical sam adapter: Adapting segment anything model for medical image segmentation
  • Polyp-sam: Transfer SAM for polyp segmentation
  • Medsam2: Segment anything in 3d medical images and videos
  • SAM 2: Segment Anything in Images and Videos
  • Segment anything model for medical images?
  • Diffusion models for implicit image segmentation ensembles
  • Stable diffusion segmentation for biomedical images with single-step reverse process
  • Tsldseg: A texture-aware and semantic-enhanced latent diffusion model for medical image segmentation
  • A generalist framework for panoptic segmentation of images and videos
  • Seggen: Supercharging segmentation models with text2mask and mask2img synthesis (opens arXiv in a new tab)
  • A simple latent diffusion approach for panoptic segmentation and mask inpainting
  • Unleashing text-to-image diffusion models for visual perception
  • Enhancing label-efficient medical image segmentation with text-guided diffusion models
  • Diffdgss: Generalizable retinal image segmentation with deterministic representation from diffusion models
  • Genmed: A pairwise generative reformulation of medical diagnostic tasks
  • Diffusion models in medical imaging: A comprehensive survey
  • High-resolution image synthesis with latent diffusion models
  • Adding conditional control to text-to-image diffusion models
  • T2i-adapter: Learning adapters to dig out more controllable ability for text-to-image diffusion models
  • Pix2seq: A language modeling framework for object detection
  • Clip-driven universal model for organ segmentation and tumor detection
  • Kvasir-seg: A segmented polyp dataset
  • Wm-dova maps for accurate polyp highlighting in colonoscopy: Validation vs. saliency maps from physicians
  • Automated polyp detection in colonoscopy videos using shape and context information
  • Toward embedded detection of polyps in wce images for early diagnosis of colorectal cancer
  • A multi-centre polyp detection and segmentation dataset for generalisability assessment
  • Skin lesion analysis toward melanoma detection: A challenge at the 2017 international symposium on biomedical imaging (isbi), hosted by the international skin imaging collaboration (isic)
  • Denoising diffusion implicit models