Datasets:
ziq
/

Languages:
English
Multilinguality:
monolingual
Size Categories:
10K<n<100K
Language Creators:
found
expert-generated
Annotations Creators:
other
Source Datasets:
extended|other
Tags:
License:
patient_id
int64
1.52k
65.5k
series_id
int64
137
64.5k
frame_id
int64
0
1.04k
image
imagewidth (px)
512
882
mask
imagewidth (px)
512
882
liver
int16
0
1
spleen
int16
0
1
right_kidney
int16
0
1
left_kidney
int16
0
1
bowel
int16
0
1
aortic_hu
int16
87
736
incomplete_organ
int16
0
1
bowel_healthy
int16
0
1
bowel_injury
int16
0
1
extravasation_healthy
int16
0
1
extravasation_injury
int16
0
1
kidney_healthy
int16
0
1
kidney_low
int16
0
1
kidney_high
int16
0
1
liver_healthy
int16
0
1
liver_low
int16
0
1
liver_high
int16
0
1
spleen_healthy
int16
0
1
spleen_low
int16
0
1
spleen_high
int16
0
1
any_injury
int16
1
1
10,004
21,057
0
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
10
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
100
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,000
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,001
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,002
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,003
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,004
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,005
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,006
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,007
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,008
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,009
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
101
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,010
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,011
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,012
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,013
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,014
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,015
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,016
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,017
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,018
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,019
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
102
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,020
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
1,021
0
0
0
0
0
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
103
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
104
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
105
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
106
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
107
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
108
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
109
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
11
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
110
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
111
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
112
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
113
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
114
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
115
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
116
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
117
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
118
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
119
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
12
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
120
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
121
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
122
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
123
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
124
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
125
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
126
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
127
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
128
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
129
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
13
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
130
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
131
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
132
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
133
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
134
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
135
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
136
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
137
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
138
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
139
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
14
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
140
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
141
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
142
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
143
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
144
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
145
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
146
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
147
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
148
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
149
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
15
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
150
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
151
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
152
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
153
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
154
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
155
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
156
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
157
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
158
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
159
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
16
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
160
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
161
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
162
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
163
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
164
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
165
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
166
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
167
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
10,004
21,057
168
0
0
0
0
1
146
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1

πŸ“ Dataset

This dataset only comprised of 205 series of CT scans in .png file with raw images and raw mask.

Data source: Kaggle RSNA 2023 Abdominal Trauma Detection

πŸš€ Setup

pip install datasets

🀩 Feel the Magic

Load Dataset

from datasets import load_dataset

data = load_dataset('ziq/RSNA-ATD2023')
print(data)
DatasetDict({
    train: Dataset({
        features: ['patient_id', 'series_id', 'frame_id', 'image', 'mask'],
        num_rows: 70291
    })
})

Set Labels

labels = ["background", "liver", "spleen", "right_kidney", "left_kidney", "bowel"]

Train Test Split

data = data['train'].train_test_split(test_size=0.2)
train, test = data['train'], data['test']

# train[0]['patient_id']
# train[0]['image'] -> PIL Image
# train[0]['mask'] -> PIL Image

Get Image & Segmentation Mask

ids = 3
image, mask = train[ids]['image'], \ # shape: (512, 512)
                  train[ids]['mask']  # shape: (512, 512)

Convert mask into np.ndarray

mask = np.array(mask)

Visualize Image & Mask

fig = plt.figure(figsize=(16,16))
ax1 = fig.add_subplot(131)
plt.axis('off')
ax1.imshow(image, cmap='gray')
ax2 = fig.add_subplot(132)
plt.axis('off')
ax2.imshow(mask, cmap='gray')
ax3 = fig.add_subplot(133)
ax3.imshow(image*np.where(mask>0,1,0), cmap='gray')
plt.axis('off')
plt.show()

raw cmap

Write Custom Plotting Function

from matplotlib.colors import ListedColormap, BoundaryNorm

colors = ['#02020e', '#520e6d', '#c13a50', '#f57d15', '#fac62c', '#f4f88e'] # inferno
bounds = range(0, len(colors) + 1)

# Define the boundaries for each class in the colormap
cmap, norm = ListedColormap(colors), BoundaryNorm(bounds, len(colors))

# Plot the segmentation mask with the custom colormap
def plot_mask(mask, alpha=1.0):
    _, ax = plt.subplots()
    cax = ax.imshow(mask, cmap=cmap, norm=norm, alpha=alpha)
    cbar = plt.colorbar(cax, cmap=cmap, norm=norm, boundaries=bounds, ticks=bounds)
    cbar.set_ticks([])
    _labels = [""] + labels
    for i in range(1, len(_labels)):
        cbar.ax.text(2, -0.5 + i, _labels[i], ha='left', color=colors[i - 1], fontsize=8)
    plt.axis('off')
    plt.show()
    

Custom Color

plot_mask(mask)

custom cmap

Plot only one class (e.g. liver)

liver, spleen, right_kidney, left_kidney, bowel = [(mask == i,1,0)[0] * i for i in range(1, len(labels))]
plot_mask(liver)

liver

Downloads last month
0
Edit dataset card