SSD-DIS: A Semi-Synthetic Shadow Dataset for Document Images.
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 158 lines · 7.9 KB · no license
- import os
- import random
- from PIL import Image
- import torchvision.transforms as transforms
- from torchvision.io import read_image
- # ============================================================================
- # CONFIGURATION PARAMETERS - USERS CAN MODIFY THESE PATHS AND PARAMETERS
- # ============================================================================
- # Shadow mask library folder (contains all available shadow mask images)
- SHADOW_MASK_LIBRARY_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\shadows'
- # Shadow-free document images folder (users need to provide their own shadow-free document images)
- # Note: Choose the appropriate folder based on your needs (train, val, or test)
- SHADOW_FREE_IMAGES_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\shadow_free_images\\test' # Change to 'train' or 'val' as needed
- # Output folder settings (it's recommended to create these directories before running)
- OUTPUT_SHADOW_MASKS_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\vers_shadow_masks\\val'
- OUTPUT_SHADOW_IMAGES_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\vers_shadow_images\\val'
- OUTPUT_ADJUSTED_MASKS_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\vers_shadow_masks_intensity_adjusted\\val'
- # Shadow intensity range (calibrated based on human perception, recommended: 0.15-0.8)
- # The intensity range used in the paper is (0.15, 0.8)
- SHADOW_INTENSITY_RANGE = (0.15, 0.8) # Can be adjusted to (0.8, 1.0) for stronger shadows
- # ============================================================================
- # MAIN PROGRAM STARTS HERE
- # ============================================================================
- def synthesize_shadow_dataset():
- """
- Main function: Batch synthesize document shadow dataset
- Functionality: Randomly select masks from the shadow mask library, resize them,
- and apply them to shadow-free document images to generate
- document images with synthetic shadows and corresponding shadow masks.
- """
- # 1. Check if input directories exist
- if not os.path.exists(SHADOW_FREE_IMAGES_DIR):
- print(f"Error: Shadow-free images directory does not exist - {SHADOW_FREE_IMAGES_DIR}")
- return
- if not os.path.exists(SHADOW_MASK_LIBRARY_DIR):
- print(f"Error: Shadow mask library directory does not exist - {SHADOW_MASK_LIBRARY_DIR}")
- return
- # 2. Create output directories if they don't exist
- for output_dir in [OUTPUT_SHADOW_MASKS_DIR, OUTPUT_SHADOW_IMAGES_DIR, OUTPUT_ADJUSTED_MASKS_DIR]:
- os.makedirs(output_dir, exist_ok=True)
- # 3. Get all shadow-free document image files
- shadow_free_files = [f for f in os.listdir(SHADOW_FREE_IMAGES_DIR)
- if os.path.isfile(os.path.join(SHADOW_FREE_IMAGES_DIR, f))]
- print(f"Starting to process {len(shadow_free_files)} shadow-free document images...")
- print(f"Shadow intensity range: {SHADOW_INTENSITY_RANGE[0]:.2f} - {SHADOW_INTENSITY_RANGE[1]:.2f}")
- print(f"Output directory: {OUTPUT_SHADOW_IMAGES_DIR}")
- # 4. Get all mask files from the shadow mask library
- shadow_mask_files = os.listdir(SHADOW_MASK_LIBRARY_DIR)
- if not shadow_mask_files:
- print("Error: No image files found in the shadow mask library")
- return
- # 5. Process each shadow-free document image
- for shadow_free_file in shadow_free_files:
- # 5.1 Randomly select a shadow mask from the library
- random_mask_file = random.choice(shadow_mask_files)
- # 5.2 Read the original shadow mask and resize it to match the document image
- mask_source_path = os.path.join(SHADOW_MASK_LIBRARY_DIR, random_mask_file)
- mask_target_path = os.path.join(OUTPUT_SHADOW_MASKS_DIR, shadow_free_file)
- # Open the shadow mask and resize it
- with Image.open(mask_source_path) as mask_img:
- # Read the corresponding shadow-free document image to get the target size
- shadow_free_path = os.path.join(SHADOW_FREE_IMAGES_DIR, shadow_free_file)
- with Image.open(shadow_free_path) as doc_img:
- # Resize the shadow mask to the same dimensions as the document image
- resized_mask = mask_img.resize(doc_img.size, Image.Resampling.LANCZOS)
- # Save the resized mask
- resized_mask.save(mask_target_path)
- print(f"Processing: {shadow_free_file} | Using mask: {random_mask_file} | Saved to: {mask_target_path}")
- # 5.3 Synthesize the shadowed document image
- synthesize_shadow_image(shadow_free_file)
- print("=" * 80)
- print("Data processing completed!")
- print(f"Number of generated shadowed images: {len(shadow_free_files)}")
- print(f"Output file locations:")
- print(f" - Shadow masks: {OUTPUT_SHADOW_MASKS_DIR}")
- print(f" - Synthetic shadow images: {OUTPUT_SHADOW_IMAGES_DIR}")
- print(f" - Adjusted masks: {OUTPUT_ADJUSTED_MASKS_DIR}")
- def synthesize_shadow_image(shadow_free_filename):
- """
- Synthesize a single shadowed document image
- Parameters:
- shadow_free_filename: Filename of the shadow-free document image
- """
- # 1. Read the shadow-free document image
- shadow_free_path = os.path.join(SHADOW_FREE_IMAGES_DIR, shadow_free_filename)
- shadow_free_image = read_image(shadow_free_path)
- # 2. Read the resized shadow mask
- shadow_mask_path = os.path.join(OUTPUT_SHADOW_MASKS_DIR, shadow_free_filename)
- shadow_mask = read_image(shadow_mask_path)
- # 3. Generate random shadow intensity for the current image
- # Note: Using the globally defined SHADOW_INTENSITY_RANGE
- shadow_intensity = random.uniform(SHADOW_INTENSITY_RANGE[0], SHADOW_INTENSITY_RANGE[1])
- # 4. Convert the shadow mask to a tensor and adjust intensity
- # Shadow masks are typically binary images (0-255), normalize to 0-1 range
- shadow_tensor = 1.0 - shadow_mask.float() / 255.0
- # Apply shadow intensity: shadowed area = shadow_intensity, non-shadowed area = 1.0
- shadow_tensor = shadow_intensity + (1.0 - shadow_intensity) * shadow_tensor
- # 5. Normalize the shadow-free document image to [0, 1] range
- shadow_free_tensor = shadow_free_image.float() / 255.0
- # 6. Expand the channel dimension of the shadow tensor to match the document image (single-channel -> three-channel)
- shadow_tensor = shadow_tensor.expand_as(shadow_free_tensor)
- # 7. Apply shadow: Multiply the document image with the shadow tensor
- # Shadowed areas become darker, non-shadowed areas remain unchanged
- shadowed_image = shadow_free_tensor * shadow_tensor
- # 8. Save the synthesized shadowed document image
- shadowed_image = (shadowed_image * 255.0).byte() # Convert back to [0, 255] range
- output_image_path = os.path.join(OUTPUT_SHADOW_IMAGES_DIR, shadow_free_filename)
- transforms.ToPILImage()(shadowed_image).save(output_image_path)
- # 9. Save the intensity-adjusted shadow mask (inverted, for visualization)
- # Invert the shadow tensor: shadowed area = 0, non-shadowed area = 1
- adjusted_mask = 1.0 - shadow_tensor
- adjusted_mask = (adjusted_mask * 255.0).byte()
- adjusted_mask_path = os.path.join(OUTPUT_ADJUSTED_MASKS_DIR, shadow_free_filename)
- transforms.ToPILImage()(adjusted_mask).save(adjusted_mask_path)
- # ============================================================================
- # PROGRAM ENTRY POINT
- # ============================================================================
- if __name__ == "__main__":
- # Print program information
- print("=" * 80)
- print("SSD-DIS Dataset Generation Tool")
- print("Function: Synthesize shadowed document images from shadow-free images and shadow mask library")
- print("=" * 80)
- # Execute the synthesis process
- synthesize_shadow_dataset()
batch_synthesize.py at commit 1fee5d2, no license · at the source
Overview
- School of Software, Northwestern Polytechnical University,Xi’an, China
- National Engineering Laboratory for Big Data System Computing Technology, Shenzhen University,Shenzhen, China
- Xi’an Institute of Optics and Precision Mechanics, Chinese Academy of Sciences,Xi’an, China
Abstract
The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repository
Its files are read in the Code ↔ Paper reader above.
Jane54542/SSD-DIS
1fee5d297895fe2b02579ed5e6e00f758caef3cd, 4 February 2026Availability: 1 check, the latest on 28 September 2026: the link answers
- 28 September 2026: the link answers
2 files
- For_synthesis/
batch_synthesize.py , Python, 158 lines - README.md, Text, 100 lines
Code availability statement
The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to the authors' code: Jane54542/
SSD-DIS
Read it in the paper: doi.org/10.1038/s41597-026-07204-4.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 1 script, each with its path and the digest of its content;
- no match between paragraphs and code yet;
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- figshare:29401811, at figshare; found in “Data availability”
- pan.baidu.com/
s/ , at pan.baidu.com; found in “Code availability”5zmiphogzz1kqi0kxfl93aq
Data availability statement
The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to 2 datasets: figshare 29401811, pan.baidu.com/
s/ 5zmiphogzz1kqi0kxfl93aq
Read it in the paper: doi.org/10.1038/s41597-026-07204-4.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 28 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 3 keywords, 14 references.
Cite
This paper
Wang, B., Li, J., Wang, Z., & Shangguan, A. (2026). SSD-DIS: A Semi-Synthetic Shadow Dataset for Document Images. Scientific data, 13(1), 1002. https://
BibTeX
@article{wang2026ssd,
author = {Wang, Bingshu and Li, Jia and Wang, Ze and Shangguan, Aihong},
title = {{SSD-DIS: A Semi-Synthetic Shadow Dataset for Document Images}},
journal = {Scientific data},
year = {2026},
month = may,
volume = {13},
number = {1},
pages = {1002},
publisher = {Nature Publishing Group},
issn = {2052-4463},
doi = {10.1038/
url = {https://
pmid = {42069718},
pmcid = {PMC13342580}
}
RIS
TY - JOUR
AU - Wang, Bingshu
AU - Li, Jia
AU - Wang, Ze
AU - Shangguan, Aihong
TI - SSD-DIS: A Semi-Synthetic Shadow Dataset for Document Images
T2 - Scientific data
J2 - Sci Data
PY - 2026
DA - 2026/
VL - 13
IS - 1
SP - 1002
SN - 2052-4463
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "SSD-DIS: A Semi-Synthetic Shadow Dataset for Document Images",
"container-title": "Scientific data",
"author": [
{
"family": "Wang",
"given": "Bingshu"
},
{
"family": "Li",
"given": "Jia"
},
{
"family": "Wang",
"given": "Ze"
},
{
"family": "Shangguan",
"given": "Aihong"
}
],
"container-title-short":
"volume": "13",
"issue": "1",
"page": "1002",
"DOI": "10.1038/
"PMID": "42069718",
"PMCID": "PMC13342580",
"ISSN": "2052-4463",
"publisher": "Nature Publishing Group",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
2
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.7554/elife.110588 [code]
- Opening the black box toward a modular approach to spike sorting.Journal: eLifeIn common: Pillow, PyTorch, methods / tools
- [2] doi:10.1038/s41598-026-61605-4 [code]
- Learning precise segmentation of neurofibrillary tangles from rapid manual point annotations.Journal: Scientific reportsIn common: Pillow, PyTorch, methods / tools
- [3] doi:10.1126/sciadv.aed3650 [code]
- Truthful visualizations for mass spectrometry imaging enable high-spatial-resolution interactive &
lt;i& gt;m/ z& lt;/ i& gt; mapping and exploration. Journal: Science advancesIn common: Pillow, PyTorch, methods / tools - [4] doi:10.3390/s26175388 [code]
- Self-Supervised Stacked Masked Denoising Autoencoder (S&
lt;sup& gt;2& lt;/ sup& gt;MDAE) for Brain MRI Denoising and Feature Learning. Journal: Sensors (Basel, Switzerland)In common: Pillow, PyTorch, methods / tools - [5] doi:10.1038/s41592-026-03194-8 [code]
- Beyond benchmarking: an expert-guided consensus approach to spatially aware clustering.Journal: Nature methodsIn common: Pillow, PyTorch, methods / tools
- [6] doi:10.1038/s41467-026-76939-w [code]
- HIPPIE: a generative model for electrophysiological analysis across species, technologies, and modalities.Journal: Nature communicationsIn common: Pillow, PyTorch, methods / tools
- [7] doi:10.1002/mrm.70496 [code]
- A Deep Nonlinear Subspace Modeling and Reconstruction for Diffusion-Weighted Imaging Using Denoising Auto-Encoder.Journal: Magnetic resonance in medicineIn common: Pillow, PyTorch, methods / tools
- [8] doi:10.1093/bioinformatics/btag540 [code]
- Deciphering spatial heterogeneity by multimodal spatial transcriptomics modelling with SpatialModal.Journal: Bioinformatics (Oxford, England)In common: Pillow, PyTorch, methods / tools
- [9] doi:10.1371/journal.pcbi.1013441 [code]
- Large vision model framework for automated C. elegans analysis: From static morphometry to dynamic neural activity.Journal: PLoS computational biologyIn common: Pillow, PyTorch, methods / tools
- [10] doi:10.1007/s12021-026-09803-3 [code]
- NeuroFusion: A Unified Framework for Generalized Visual Stimulus Decoding from fMRI Across Datasets and Subjects.Journal: NeuroinformaticsIn common: Pillow, PyTorch, methods / tools
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 1 script, and 0 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:b75f7dbaa206e4e2…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
