OSCR

SSD-DIS: A Semi-Synthetic Shadow Dataset for Document Images.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

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

  1. import os
  2. import random
  3. from PIL import Image
  4. import torchvision.transforms as transforms
  5. from torchvision.io import read_image
  6. # ============================================================================
  7. # CONFIGURATION PARAMETERS - USERS CAN MODIFY THESE PATHS AND PARAMETERS
  8. # ============================================================================
  9. # Shadow mask library folder (contains all available shadow mask images)
  10. SHADOW_MASK_LIBRARY_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\shadows'
  11. # Shadow-free document images folder (users need to provide their own shadow-free document images)
  12. # Note: Choose the appropriate folder based on your needs (train, val, or test)
  13. SHADOW_FREE_IMAGES_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\shadow_free_images\\test' # Change to 'train' or 'val' as needed
  14. # Output folder settings (it's recommended to create these directories before running)
  15. OUTPUT_SHADOW_MASKS_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\vers_shadow_masks\\val'
  16. OUTPUT_SHADOW_IMAGES_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\vers_shadow_images\\val'
  17. OUTPUT_ADJUSTED_MASKS_DIR = 'D:\\shadow_document_datasets\\semi-synthetic dataset\\vers_shadow_masks_intensity_adjusted\\val'
  18. # Shadow intensity range (calibrated based on human perception, recommended: 0.15-0.8)
  19. # The intensity range used in the paper is (0.15, 0.8)
  20. SHADOW_INTENSITY_RANGE = (0.15, 0.8) # Can be adjusted to (0.8, 1.0) for stronger shadows
  21. # ============================================================================
  22. # MAIN PROGRAM STARTS HERE
  23. # ============================================================================
  24. def synthesize_shadow_dataset():
  25. """
  26. Main function: Batch synthesize document shadow dataset
  27. Functionality: Randomly select masks from the shadow mask library, resize them,
  28. and apply them to shadow-free document images to generate
  29. document images with synthetic shadows and corresponding shadow masks.
  30. """
  31. # 1. Check if input directories exist
  32. if not os.path.exists(SHADOW_FREE_IMAGES_DIR):
  33. print(f"Error: Shadow-free images directory does not exist - {SHADOW_FREE_IMAGES_DIR}")
  34. return
  35. if not os.path.exists(SHADOW_MASK_LIBRARY_DIR):
  36. print(f"Error: Shadow mask library directory does not exist - {SHADOW_MASK_LIBRARY_DIR}")
  37. return
  38. # 2. Create output directories if they don't exist
  39. for output_dir in [OUTPUT_SHADOW_MASKS_DIR, OUTPUT_SHADOW_IMAGES_DIR, OUTPUT_ADJUSTED_MASKS_DIR]:
  40. os.makedirs(output_dir, exist_ok=True)
  41. # 3. Get all shadow-free document image files
  42. shadow_free_files = [f for f in os.listdir(SHADOW_FREE_IMAGES_DIR)
  43. if os.path.isfile(os.path.join(SHADOW_FREE_IMAGES_DIR, f))]
  44. print(f"Starting to process {len(shadow_free_files)} shadow-free document images...")
  45. print(f"Shadow intensity range: {SHADOW_INTENSITY_RANGE[0]:.2f} - {SHADOW_INTENSITY_RANGE[1]:.2f}")
  46. print(f"Output directory: {OUTPUT_SHADOW_IMAGES_DIR}")
  47. # 4. Get all mask files from the shadow mask library
  48. shadow_mask_files = os.listdir(SHADOW_MASK_LIBRARY_DIR)
  49. if not shadow_mask_files:
  50. print("Error: No image files found in the shadow mask library")
  51. return
  52. # 5. Process each shadow-free document image
  53. for shadow_free_file in shadow_free_files:
  54. # 5.1 Randomly select a shadow mask from the library
  55. random_mask_file = random.choice(shadow_mask_files)
  56. # 5.2 Read the original shadow mask and resize it to match the document image
  57. mask_source_path = os.path.join(SHADOW_MASK_LIBRARY_DIR, random_mask_file)
  58. mask_target_path = os.path.join(OUTPUT_SHADOW_MASKS_DIR, shadow_free_file)
  59. # Open the shadow mask and resize it
  60. with Image.open(mask_source_path) as mask_img:
  61. # Read the corresponding shadow-free document image to get the target size
  62. shadow_free_path = os.path.join(SHADOW_FREE_IMAGES_DIR, shadow_free_file)
  63. with Image.open(shadow_free_path) as doc_img:
  64. # Resize the shadow mask to the same dimensions as the document image
  65. resized_mask = mask_img.resize(doc_img.size, Image.Resampling.LANCZOS)
  66. # Save the resized mask
  67. resized_mask.save(mask_target_path)
  68. print(f"Processing: {shadow_free_file} | Using mask: {random_mask_file} | Saved to: {mask_target_path}")
  69. # 5.3 Synthesize the shadowed document image
  70. synthesize_shadow_image(shadow_free_file)
  71. print("=" * 80)
  72. print("Data processing completed!")
  73. print(f"Number of generated shadowed images: {len(shadow_free_files)}")
  74. print(f"Output file locations:")
  75. print(f" - Shadow masks: {OUTPUT_SHADOW_MASKS_DIR}")
  76. print(f" - Synthetic shadow images: {OUTPUT_SHADOW_IMAGES_DIR}")
  77. print(f" - Adjusted masks: {OUTPUT_ADJUSTED_MASKS_DIR}")
  78. def synthesize_shadow_image(shadow_free_filename):
  79. """
  80. Synthesize a single shadowed document image
  81. Parameters:
  82. shadow_free_filename: Filename of the shadow-free document image
  83. """
  84. # 1. Read the shadow-free document image
  85. shadow_free_path = os.path.join(SHADOW_FREE_IMAGES_DIR, shadow_free_filename)
  86. shadow_free_image = read_image(shadow_free_path)
  87. # 2. Read the resized shadow mask
  88. shadow_mask_path = os.path.join(OUTPUT_SHADOW_MASKS_DIR, shadow_free_filename)
  89. shadow_mask = read_image(shadow_mask_path)
  90. # 3. Generate random shadow intensity for the current image
  91. # Note: Using the globally defined SHADOW_INTENSITY_RANGE
  92. shadow_intensity = random.uniform(SHADOW_INTENSITY_RANGE[0], SHADOW_INTENSITY_RANGE[1])
  93. # 4. Convert the shadow mask to a tensor and adjust intensity
  94. # Shadow masks are typically binary images (0-255), normalize to 0-1 range
  95. shadow_tensor = 1.0 - shadow_mask.float() / 255.0
  96. # Apply shadow intensity: shadowed area = shadow_intensity, non-shadowed area = 1.0
  97. shadow_tensor = shadow_intensity + (1.0 - shadow_intensity) * shadow_tensor
  98. # 5. Normalize the shadow-free document image to [0, 1] range
  99. shadow_free_tensor = shadow_free_image.float() / 255.0
  100. # 6. Expand the channel dimension of the shadow tensor to match the document image (single-channel -> three-channel)
  101. shadow_tensor = shadow_tensor.expand_as(shadow_free_tensor)
  102. # 7. Apply shadow: Multiply the document image with the shadow tensor
  103. # Shadowed areas become darker, non-shadowed areas remain unchanged
  104. shadowed_image = shadow_free_tensor * shadow_tensor
  105. # 8. Save the synthesized shadowed document image
  106. shadowed_image = (shadowed_image * 255.0).byte() # Convert back to [0, 255] range
  107. output_image_path = os.path.join(OUTPUT_SHADOW_IMAGES_DIR, shadow_free_filename)
  108. transforms.ToPILImage()(shadowed_image).save(output_image_path)
  109. # 9. Save the intensity-adjusted shadow mask (inverted, for visualization)
  110. # Invert the shadow tensor: shadowed area = 0, non-shadowed area = 1
  111. adjusted_mask = 1.0 - shadow_tensor
  112. adjusted_mask = (adjusted_mask * 255.0).byte()
  113. adjusted_mask_path = os.path.join(OUTPUT_ADJUSTED_MASKS_DIR, shadow_free_filename)
  114. transforms.ToPILImage()(adjusted_mask).save(adjusted_mask_path)
  115. # ============================================================================
  116. # PROGRAM ENTRY POINT
  117. # ============================================================================
  118. if __name__ == "__main__":
  119. # Print program information
  120. print("=" * 80)
  121. print("SSD-DIS Dataset Generation Tool")
  122. print("Function: Synthesize shadowed document images from shadow-free images and shadow mask library")
  123. print("=" * 80)
  124. # Execute the synthesis process
  125. synthesize_shadow_dataset()

batch_synthesize.py at commit 1fee5d2, no license · at the source

Overview

Authors: Bingshu Wang1,2, Jia Li1, Ze Wang1, Aihong Shangguan3
  1. School of Software, Northwestern Polytechnical University,Xi’an, China
  2. National Engineering Laboratory for Big Data System Computing Technology, Shenzhen University,Shenzhen, China
  3. Xi’an Institute of Optics and Precision Mechanics, Chinese Academy of Sciences,Xi’an, China
Journal: Scientific data, volume 13, issue 1, article 1002
Dates: received 8 October 2025; accepted 31 March 2026; published online 2 May 2026
Type: Data paper · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41597-026-07204-4 · PMID 42069718 · PMCID PMC13342580 · OpenAlex W7159956382
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: methods / tools (subfield)
Keywords: Computer science, Scientific data, Mathematics and computing
Journal subjects: Data Descriptor
Topic: Handwritten Text Recognition Techniques (Computer Vision and Pattern Recognition, Computer Science), according to OpenAlex
Citations: not cited yet (Europe PMC); 19 references in the paper

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

License: none: the authors keep all their rights
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: 1fee5d297895fe2b02579ed5e6e00f758caef3cd, 4 February 2026
Languages: Python (1)
Size: 2 files, 1 script
Software Heritage: not archived
Found in: “Code availability”
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Pillow (1 file), PyTorch (1 file)
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
2 files

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:

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

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:

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://doi.org/10.1038/s41597-026-07204-4

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/s41597-026-07204-4},
url = {https://doi.org/10.1038/s41597-026-07204-4},
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/05/02
VL - 13
IS - 1
SP - 1002
SN - 2052-4463
PB - Nature Publishing Group
DO - 10.1038/s41597-026-07204-4
UR - https://doi.org/10.1038/s41597-026-07204-4
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41597-026-07204-4",
"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": "Sci Data",
"volume": "13",
"issue": "1",
"page": "1002",
"DOI": "10.1038/s41597-026-07204-4",
"PMID": "42069718",
"PMCID": "PMC13342580",
"ISSN": "2052-4463",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41597-026-07204-4",
"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: eLife
In 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 reports
In common: Pillow, PyTorch, methods / tools
[3] doi:10.1126/sciadv.aed3650 [code]
Truthful visualizations for mass spectrometry imaging enable high-spatial-resolution interactive <i>m/z</i> mapping and exploration.
Journal: Science advances
In common: Pillow, PyTorch, methods / tools
[4] doi:10.3390/s26175388 [code]
Self-Supervised Stacked Masked Denoising Autoencoder (S<sup>2</sup>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 methods
In 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 communications
In 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 medicine
In 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 biology
In 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: Neuroinformatics
In 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.

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.