File size: 3,189 Bytes
71cfd9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391b5e5
71cfd9a
 
391b5e5
71cfd9a
 
391b5e5
71cfd9a
 
 
 
 
 
 
391b5e5
 
 
 
 
 
71cfd9a
391b5e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f58d6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391b5e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
dataset_info:
  features:
  - name: image
    dtype: image
  - name: tl
    sequence: int64
  - name: tr
    sequence: int64
  - name: br
    sequence: int64
  - name: bl
    sequence: int64
  - name: is_clean
    dtype: bool
  - name: split
    dtype: string
  - name: text
    dtype: string
  - name: image_name
    dtype: string
  splits:
  - name: validation
    num_bytes: 64018244
    num_examples: 101
  - name: test
    num_bytes: 125460818
    num_examples: 199
  download_size: 189448472
  dataset_size: 189479062
configs:
- config_name: default
  data_files:
  - split: validation
    path: data/validation-*
  - split: test
    path: data/test-*
license: mit
task_categories:
- image-to-text
- object-detection
size_categories:
- n<1K
---

# DM codes dataset

The dataset contains photos of Data Matrix (DM) codes and their annotations. The photos were taken on an iPhone and annotated manually by a human.
The annotations contain **text**, which is encoded in the DM code and the pixel coordinates of the DM code vertices.
The vertices are: **tl** = top left, **tr** = top right, **br** = bottom right, **bl** = bottom left.
Attribute **is_clean** specifies whether the DM code on the image is expected to be easily readable. For every DM code, there is exactly one image
with `is_clean=true` and several images with `is_clean=false`.

If you want to crop the DM codes from the images, use the following code:

```python
import numpy as np
import datasets
from PIL import Image
from skimage import transform

def crop_dm_code(example: dict, square_side: int = 200, square_padding: int = 25) -> dict:
    vertices = np.asarray((example["tl"], example["tr"], example["br"], example["bl"]))
    unit_square = np.asarray([
        [square_padding, square_padding],
        [square_side + square_padding, square_padding],
        [square_side + square_padding, square_side + square_padding],
        [square_padding, square_side + square_padding]
    ])
    transf = transform.ProjectiveTransform()
    if not transf.estimate(unit_square, vertices): raise Exception("estimate failed")
    cropped_np_image = transform.warp(
        np.array(example["image"]),
        transf,
        output_shape=(square_side + square_padding * 2, square_side + square_padding * 2)
    )
    cropped_image = Image.fromarray((cropped_np_image * 255).astype(np.uint8))
    return {"cropped_image": cropped_image}

dataset = datasets.load_dataset("shortery/dm-codes")
dataset = dataset.map(crop_dm_code)
```

## DataMatrix Image Reconstruction to Enhance Decodability

This dataset is a part of the Diploma thesis <https://is.muni.cz/th/ppu25/dp-dmcodes-thesis.pdf>. 
This thesis compares various encoder-decoder CNNs to enhance the DM code image quality before decoding it with a code reader.
The code is available on GitHub <https://github.com/shortery/dp-dm-codes>. 


## Citing

```
@thesis{dmcodes-thesis,
  author = {Petra Krátká},
  title = {DataMatrix Image Reconstruction to Enhance Decodability},
  address = {Brno},
  year = {2024},
  school = {Masaryk University, Faculty of Informatics},
  type = {Diploma thesis},
  url = {https://is.muni.cz/th/ppu25/dp-dmcodes-thesis.pdf},
}
```