This protocol implements a U-shaped deep learning network integrating pinwheel convolution, dual attention, and multi-scale fusion to segment colorectal polyps.
A subscription to JoVE is required to view this content. Sign in or start your free trial.
Method Article
* These authors contributed equally
This protocol implements a U-shaped deep learning network integrating pinwheel convolution, dual attention, and multi-scale fusion to segment colorectal polyps.
Accurate segmentation of colorectal polyps is crucial for the early prevention and diagnosis of colorectal cancer. However, due to the high heterogeneity of polyps in terms of shape, size, and texture, as well as the complexity of the intestinal environment (such as folds, specular reflections, and fecal residues), existing methods still face significant challenges in boundary localization and small-polyp detection. To address these issues, this paper proposes a Polyp Segmentation Network based on Pinwheel Convolution and Dual Attention (PWD-Net). The proposed network adopts a U-shaped encoder–decoder architecture, where a pretrained ResNet is employed as the encoder to extract multi-level local features. Specifically, a Pinwheel Convolution Module (PCM) is introduced at the bottleneck layer to capture the global geometric structure and multi-directional contextual information of polyps through multi-angle rotated convolution kernels. A Dual-Attention Mechanism (DAM) that integrates channel attention and spatial attention is designed to adaptively suppress background noise and enhance polyp-region features. In addition, a Multi-scale Feature Fusion (MSF) strategy is employed to combine deep semantic information with shallow boundary details, ensuring both completeness and precision of segmentation results. Experiments conducted on the Kvasir-SEG and CVC-ClinicDB datasets demonstrate that PWD-Net achieves average Dice coefficients of 0.865 and 0.944, and IoU scores of 0.765 and 0.892, respectively, significantly outperforming existing state-of-the-art methods. Ablation studies verify the effectiveness of each module, and cross-dataset evaluations confirm the strong generalization ability of the model. This study provides a high-precision and robust solution for clinical polyp segmentation, offering significant value for the early diagnosis of colorectal precancerous lesions and supporting computer-aided intervention.
Colorectal cancer is one of the most common malignant tumors worldwide, with consistently high incidence and mortality rates. Studies have shown that most colorectal cancers develop from adenomatous polyps, a process that typically takes 10–15 years, providing a valuable time window for early detection and intervention. An increase of 1% in the adenoma detection rate (ADR) can reduce the risk of colorectal cancer by approximately 3%, significantly lowering patient mortality1. Colonoscopy, regarded as the gold standard for colorectal cancer screening, enables direct removal of polyps during examination, thereby effectively reducing cancer incidence and mortality.
However, conventional colonoscopy heavily depends on the experience and skill level of endoscopists. Factors such as subjective judgment, visual fatigue, and distraction may lead to a miss rate of 20%–30%, which directly affects screening effectiveness2. Therefore, developing computer-aided detection (CAD) systems for automatic segmentation of colorectal polyps holds considerable importance for improving ADR and reducing missed diagnoses. Recent clinical surveys have further highlighted the interest in integrating artificial intelligence into endoscopic lesion assessment workflows, reinforcing the need for robust and reproducible segmentation methods3.
In recent years, deep learning has achieved remarkable progress in medical image analysis, particularly convolutional neural networks (CNNs), which demonstrate strong capability in feature extraction and representation for image segmentation tasks4. As a classical medical image segmentation model, U-Net employs a symmetric encoder–decoder architecture and skip connections to achieve accurate pixel-level segmentation, becoming a benchmark in this field5. Building upon U-Net, many improved architectures have been proposed to address complex medical image segmentation tasks. UNet++ reduces the semantic gap between encoder and decoder feature maps by introducing nested and dense skip connections6. ResUNet++ integrates residual blocks, squeeze-and-excitation modules, dilated convolutions, and attention mechanisms, achieving strong performance in polyp segmentation7. U2-Net adopts a two-level nested U-shaped structure to capture multi-scale feature information8. More recently, a dual encoder-decoder-based deep polyp segmentation network has been proposed, leveraging parallel encoding and decoding paths to further enhance segmentation accuracy9.
Meanwhile, the introduction of attention mechanisms provides new solutions for feature enhancement and noise suppression. Attention U-Net employs attention gates to focus on target regions while suppressing irrelevant background information10. The Dual Attention Network (DANet) adaptively weights features from both channel and spatial dimensions11, improving the perception of critical features. Triple Attention Networks (TANet) further enhance segmentation performance through adaptive selection of multi-scale features12.
With the success of Transformer architectures in natural language processing and computer vision13, researchers have begun exploring their application in medical image segmentation. TransUNet was the first to employ a Transformer as an encoder to model long-range dependencies effectively14. Swin-UNet adopts a pure Transformer architecture and achieves efficient global information aggregation through a shifted-window mechanism15. UTNet proposes a hybrid architecture that combines the local feature extraction capability of CNNs with the global modeling ability of Transformers16.
In the field of polyp segmentation, Polyp-PVT utilizes a pyramid vision Transformer to capture multi-scale global semantic information17, while multi-scale nested UNet enhances contextual understanding by integrating Transformers18. Recent studies have also explored negative correlation learning strategies for cross-domain polyp segmentation19, Gompertz-augmented segmentation enhancement20, and attention-based architectures incorporating boundary guidance21. Although these approaches improve segmentation performance to some extent, polyp segmentation still faces several challenges. First, polyps exhibit high heterogeneity in morphology, size, and texture, ranging from micro-polyps smaller than 5 mm to large polyps exceeding 30 mm, with shapes varying from circular and elliptical to highly irregular forms. Second, the intestinal environment is complex and variable, where mucosal folds, specular reflections, fecal residues, and food debris introduce severe background interference. Third, many polyps have blurred boundaries, may be partially occluded by folds, or submerged in intestinal fluids, making precise boundary localization extremely challenging22.
Existing methods still present clear limitations in addressing these challenges. Traditional CNNs are effective at extracting local texture and edge features; however, fixed square convolution kernels are not well suited to capturing diverse geometric shapes23, especially for highly irregular polyps, and cannot effectively model multi-directional geometric features. Transformer-based methods can model global dependencies but are less effective at capturing fine local details and boundary information. Moreover, their high computational complexity makes them less suitable for real-time clinical applications24. Recent polyp segmentation approaches such as PraNet, which uses reverse attention modules to refine key regions25, boundary-guided cascade attention networks that enhance boundary feature extraction26, and CAFE-Net, which fuses encoder and decoder features through cross-attention mechanisms27, still encounter insufficient feature representation and inaccurate boundary localization when dealing with small polyps28, blurred boundaries, and complex backgrounds. Furthermore, most methods neglect geometric morphology and fail to fully exploit multi-directional contextual information, resulting in suboptimal segmentation of irregularly shaped polyps.
In summary, current CNN-based methods lack the ability to capture multi-directional geometric features due to their reliance on fixed square convolution kernels. Transformer-based approaches offer global modeling but sacrifice local boundary precision and impose high computational costs. Meanwhile, existing attention-enhanced and multi-scale fusion strategies have not been jointly optimized within a unified framework specifically tailored for polyp segmentation29. These gaps motivate the development of a method that simultaneously addresses geometric feature modeling, adaptive noise suppression, and cross-scale feature integration.
To address these issues, this protocol presents a Polyp Segmentation Network based on Pinwheel Convolution and Dual Attention (PWD-Net). The proposed network integrates geometric feature modeling, multi-dimensional attention enhancement, and multi-scale feature fusion, enabling precise segmentation of complex polyps. The main contributions of this work are summarized as follows: the pinwheel convolution module (PCM), inspired by the structure of a pinwheel, a novel rotated convolution kernel design is proposed that captures multi-directional geometric features of polyps through convolution operations at multiple angles (0°, 45°, 90°, 135°, 180°, 225°, 270°, and 315°). This module replaces the conventional convolution layer at the bottleneck stage, enabling effective perception of diverse edge orientations and significantly improving the representation of irregularly shaped polyps. The dual-attention mechanism (DAM) addresses background noise such as folds, reflections, and fecal residues in colonoscopy images. A dual-attention module integrating channel attention and spatial attention is designed. Embedded within skip connections, this module adaptively suppresses background interference and enhances feature responses in polyp regions by jointly identifying "what" is important (channel dimension) and "where" the target is located (spatial dimension), ensuring that only refined features are involved in subsequent fusion. The multi-scale feature fusion strategy (MSF) preserves both deep semantic information and shallow boundary details through a hierarchical mechanism introduced in the decoder. By progressively integrating DAM-enhanced encoder features with upsampled decoder features, this strategy effectively compensates for spatial detail loss caused by downsampling, enabling accurate detection of small polyps and precise boundary delineation.
Access restricted. Please log in or start a trial to view this content.
This study uses only publicly available, anonymized colonoscopy image datasets (Kvasir-SEG). No new human subject data were collected. Institutional ethics approval and informed patient consent were not required, as confirmed by the institutional review policies for retrospective analyses of de-identified public datasets.
1. Data Preparation
2. Overall Architecture
NOTE: Refer to Figure 1 for the macro-level encoder–decoder backbone of PWD-Net, and to Figure 2 for the integration and interaction of core modules within the feature flow. The overall architecture follows a U-shaped encoder–decoder design to handle scale variations of polyps and background interference in colonoscopy images.
3. Pinwheel Convolution Module (Figure 3)

4. Dual-Attention Mechanism (Figure 4)
NOTE: The Dual-Attention Mechanism (DAM) is embedded within each skip connection to suppress background noise and enhance polyp-region features from both channel and spatial dimensions.


5. Multi-scale Feature Fusion
6. Loss Function and Training Configuration



7. Pseudocode
Algorithm 1: PWD-Net Polyp Segmentation
1: Input: Colonoscopy image I ∈ ℝH×W×3
2: Output: Segmentation mask M ∈ {0,1}(H×W)
3:
4: function PCM(X) ▷ Pinwheel Convolution Module
5: Define base kernel W (3 x 3), angles Θ = {0°, 45°, ..., 315°}
6: for each θ ∈ Θ do
7: Wθ ← BilinearRotate(W, θ) ▷ Rotate kernel
8: Yθ ← Conv2d(X, Wθ) ▷ Direction-specific features
9: end for
10: Yout ← ReLU(BN(Conv1 x 1(Concat({Yθ})))) ▷ Aggregate
11: return Yout
12: end function
13:
14: function DAM(F) ▷ Dual-Attention Mechanism
15: Ac ← Sigmoid(MLP(AvgPool(F))) ▷ Channel attention (r=16)
16: As ← Sigmoid(Conv7 x 7([AvgPool(F); MaxPool(F)])) ▷ Spatial attention
17: F' ← F ⊗ (α · Ac + β · As) ▷ Fuse with learnable α, β (init=0.5)
18: return F'
19: end function
20:
21: function PWD-Net(I)
22: Encoder: e1, e2, e3, e4, e5 ← ResNet50_Stages(I) ▷ 5-stage pretrained encoder
23: Bottleneck: b ← PCM(e5) ▷ Apply PCM at bottleneck
24: Skip connections: si ← DAM(ei) for i = 1, 2, 3, 4 ▷ Filter encoder features
25: Decoder:
26: d4 ← DoubleConv(Concat(Up(b), s4))
27: d3 ← DoubleConv(Concat(Up(d4), s3))
28: d2 ← DoubleConv(Concat(Up(d3), s2))
29: d1 ← DoubleConv(Concat(Up(d2), s1))
30: M ← Sigmoid(Conv1 x 1(d1))
31: return M
32: end function
33:
34: Training:
35: for each epoch do
36: M̂ ← PWD-Net(I)
37: ℒ ← 0.5 · BCE(M̂, Mgt) + 0.5 · DiceLoss(M̂, Mgt) ▷ λ = 0.5
38: Update parameters via backpropagation (Adam optimizer)
39: end for
Access restricted. Please log in or start a trial to view this content.
Experimental Setup
Dataset
The Kvasir SEG dataset was used to evaluate the segmentation behavior of PWD Net on colonoscopy images with heterogeneous polyp appearances. The dataset contains 1,000 pixel annotated polyp images and includes variation in polyp size, shape, texture, illumination, and background complexity, making it suitable for assessing small target detection, boundary localization, and robustness to visual interference. The dataset was divided into training, ...
Access restricted. Please log in or start a trial to view this content.
Several design choices in the PWD-Net protocol are critical for achieving reliable segmentation results and merit careful attention during implementation. First, the selection and initialization of the encoder backbone directly influence convergence behavior and final performance. The protocol employs a ResNet-50 encoder pretrained on ImageNet, which provides robust low-level and mid-level feature initialization. This is particularly important for medical image segmentation tasks where the available training data are lim...
Access restricted. Please log in or start a trial to view this content.
The authors have nothing to disclose.
This study was funded by the National Key R&D Program of China (Program Nos. 2022YFC3500200 and 2022YFC3500204).
Access restricted. Please log in or start a trial to view this content.
| Name | Company | Catalog Number | Comments |
|---|---|---|---|
| Adam Optimizer | — | — | Included in PyTorch |
| Albumentations | Albumentations Team | v1.0+ | Data augmentation library |
| CUDA Toolkit | NVIDIA | v11.3+ | GPU acceleration |
| Kvasir-SEG dataset | SimulaMet | — | https://datasets.simula.no/kvasir-seg/ |
| Matplotlib | Matplotlib Community | v3.4+ | Visualization of training curves |
| NumPy | NumPy Community | v1.21+ | Numerical computation |
| NVIDIA Tesla P100 | NVIDIA | P100-PCIE-16GB | GPU for training and inference |
| OpenCV | OpenCV Community | v4.5+ | Image preprocessing |
| Python | Python Software Foundation | v3.8+ | Programming language |
| PyTorch | Meta Platforms | v1.12+ | Deep learning framework |
| ResNet-50 pretrained weights | PyTorch Model Zoo | — | ImageNet-1K pretrained |
| Ubuntu | Canonical | 18.04+ | Operating system |