Image quality, copies and split leaks
Audit an image collection before it trains a model. Measure exposure and blur on one copy per image, find identical files and near-duplicates with perceptual hashes, and catch copies and shared sources that leak across a train/test split.
What runs in CodeSplash
- Image quality and duplicate audit Experimental
You will be able to
- Read quality measures taken on one analysis copy and know when sharpness misleads
- Tell identical files (same content hash) from near-duplicates (hashes a few bits apart)
- Find held-out images that copy a training image, and sources on both sides of a split
Read first
Why audit before you train
ReadA model learns whatever the pictures share. Dark frames, blurred frames and copies all change what it learns, and a copy that sits on both sides of a train/test split makes the test score look better than it is.
The audit reads each image once, as a 256 × 256 copy the app decodes for every method, so Python and R measure the same pixels.
Make a guess
PredictPredict first
The test collection holds 74 readable frames of parts on a belt. One file was copied byte for byte, and one was re-saved three gray levels brighter. How many near-duplicate pairs will the pHash find at 6 bits?
Make your guess between 0 and 20 pairs, then reveal.
Reveal
It finds 2 near-duplicate pairs and 1 identical file. The brightened copy keeps its hash: a perceptual hash compares the image with itself, not with fixed gray levels.
Exposure and blur on one copy
ExploreView data
| brightness | sharpness | flag | file |
|---|---|---|---|
| 0.0600 | 120.30 | Dark | IMG_1000.jpg |
| 0.0800 | 3,651 | Dark | IMG_1001.jpg |
| 0.1000 | 3723.60 | Dark | IMG_1002.jpg |
| 0.1200 | 173.60 | Dark | IMG_1003.jpg |
| 0.9000 | 793.30 | Bright | IMG_1004.jpg |
| 0.9200 | 5419.30 | Bright | IMG_1005.jpg |
| 0.9400 | 343.60 | Bright | IMG_1006.jpg |
| 0.8130 | 15 | Blurry | IMG_1007.jpg |
| 0.5240 | 27 | Blurry | IMG_1008.jpg |
| 0.6240 | 39 | Blurry | IMG_1009.jpg |
| 0.7470 | 51 | Blurry | IMG_1010.jpg |
| 0.6930 | 63 | Blurry | IMG_1011.jpg |
| 0.5050 | 432.40 | OK | IMG_1012.jpg |
| 0.3590 | 617.80 | OK | IMG_1013.jpg |
| 0.4440 | 409 | OK | IMG_1014.jpg |
| 0.3930 | 213.50 | OK | IMG_1015.jpg |
| 0.7640 | 1,310 | OK | IMG_1016.jpg |
| 0.4250 | 672 | OK | IMG_1017.jpg |
| 0.4200 | 106 | OK | IMG_1018.jpg |
| 0.9310 | 143.70 | Bright | IMG_1019.jpg |
| 0.1310 | 704.70 | Dark | IMG_1020.jpg |
| 0.5020 | 842.40 | OK | IMG_1021.jpg |
| 0.5370 | 289.60 | OK | IMG_1022.jpg |
| 0.6590 | 375.30 | OK | IMG_1023.jpg |
| 0.4910 | 1145.60 | OK | IMG_1024.jpg |
| 0.7960 | 1107.90 | OK | IMG_1025.jpg |
| 0.1070 | 494.20 | Dark | IMG_1026.jpg |
| 0.7020 | 453.20 | OK | IMG_1027.jpg |
| 0.5460 | 11768.20 | OK | IMG_1028.jpg |
| 0.6400 | 2192.50 | OK | IMG_1029.jpg |
| 0.4640 | 420.10 | OK | IMG_1030.jpg |
| 0.7040 | 226.50 | OK | IMG_1031.jpg |
| 0.5720 | 31.600 | Blurry | IMG_1032.jpg |
| 0.3100 | 120.80 | OK | IMG_1033.jpg |
| 0.6090 | 408.90 | OK | IMG_1034.jpg |
| 0.4460 | 1105.60 | OK | IMG_1035.jpg |
| 0.4750 | 137.40 | OK | IMG_1036.jpg |
| 0.8010 | 891.20 | OK | IMG_1037.jpg |
| 0.6110 | 173.90 | OK | IMG_1038.jpg |
| 0.4450 | 1016.80 | OK | IMG_1039.jpg |
| 0.5720 | 2469.40 | OK | IMG_1040.jpg |
| 0.4830 | 791.70 | OK | IMG_1041.jpg |
| 0.8100 | 119.60 | OK | IMG_1042.jpg |
| 0.4090 | 783.20 | OK | IMG_1043.jpg |
| 0.6830 | 1022.10 | OK | IMG_1044.jpg |
| 0.2740 | 569.10 | OK | IMG_1045.jpg |
| 0.3510 | 3901.90 | OK | IMG_1046.jpg |
| 0.4440 | 1414.90 | OK | IMG_1047.jpg |
| 0.7400 | 598.50 | OK | IMG_1048.jpg |
| 0.4050 | 92.200 | Blurry | IMG_1049.jpg |
| 0.4080 | 749.20 | OK | IMG_1050.jpg |
| 0.3620 | 179 | OK | IMG_1051.jpg |
| 0.5710 | 1313.10 | OK | IMG_1052.jpg |
| 0.7420 | 330.20 | OK | IMG_1053.jpg |
| 0.7550 | 1260.20 | OK | IMG_1054.jpg |
| 0.8030 | 941.80 | OK | IMG_1055.jpg |
| 0.2490 | 2,510 | OK | IMG_1056.jpg |
| 0.7290 | 93.600 | Duplicate | IMG_1057.jpg |
| 0.6330 | 904.90 | Duplicate | IMG_1058.jpg |
| 0.9450 | 100.90 | Duplicate | IMG_1059.jpg |
Brightness and contrast come from the luma of the copy; sharpness is the variance of the LaplacianVariance of the LaplacianThe variance of an image's second-derivative (edge) response: sharp images have strong edges and a high value, blurry ones a low value.. Measuring every image at 256 × 256 makes them comparable, but a small original is enlarged first and comes out soft. In the test collection the frames are about 32 pixels wide, so 70 of them fall below the default blur threshold.
Check yourself
Most images in a collection are flagged blurry, and the size chart shows they are 40 pixels wide. What's the most likely reason?
Show the answer
Answer: b
Sharpness depends on scale. Compare sharpness between images of similar size, or lower the threshold for a collection of thumbnails.
Copies: same bytes or same look
CheckpointTwo kinds of copy show up in the pairs table:
- Identical files share a content hash (the collection's
media_id, blake3 of the bytes). They are the same file saved twice. - Near-duplicates have perceptual hashesPerceptual hashA 64-bit fingerprint of an image's coarse brightness pattern; resized, re-saved or lightly edited copies get fingerprints a few bits apart. a few bits apart: resized, re-encoded or lightly edited. pHash is the default; dHash and aHashDifference and average hashes (dHash, aHash)64-bit fingerprints: dHash notes whether each pixel of a tiny copy is brighter than its left neighbor, aHash whether it beats the mean. are offered too, and all three are saved per image.
Check yourself
A near-duplicate pair has hashes 2 bits apart and different content hashes. What do you know?
Show the answer
Answer: b
Different content hashes mean different bytes; close perceptual hashes mean similar pictures. Look at the pair before deciding: on an inspection line, good parts can look alike without being copies.
Leaks across the split
Explore74 images: 1 dark, 0 bright, 70 blurry; 1 identical copies, 2 near-duplicate pairs.
- Images read
- 74
- Mean brightness
- 0.3786
- Median sharpness
- 1.513
- Identical copies
- 1
- Near-duplicate pairs
- 2
Plots
View data
| Brightness (0–1) | Flag | File | Sharpness (variance of the Laplacian) |
|---|---|---|---|
| 0.3951 | Blurry | good_00.png | 1.052 |
| 0.3771 | Blurry | good_01.png | 1.499 |
| 0.3765 | Blurry | good_02.png | 1.568 |
| 0.3952 | Blurry | good_03.png | 1.093 |
| 0.3771 | Blurry | good_04.png | 1.489 |
| 0.3765 | Blurry | good_05.png | 1.537 |
| 0.3952 | Blurry | good_06.png | 1.049 |
| 0.3768 | Blurry | good_07.png | 1.490 |
| 0.3764 | Blurry | good_08.png | 1.537 |
| 0.3954 | Blurry | good_09.png | 1.079 |
| 0.3772 | Blurry | good_10.png | 1.481 |
| 0.3766 | Blurry | good_11.png | 1.505 |
| 0.3954 | Blurry | good_12.png | 1.076 |
| 0.3770 | Blurry | good_13.png | 1.519 |
| 0.3767 | Blurry | good_14.png | 1.517 |
| 0.3957 | Blurry | good_15.png | 1.057 |
| 0.3775 | Blurry | good_16.png | 1.571 |
| 0.3766 | Blurry | good_17.png | 1.542 |
| 0.3953 | Blurry | good_18.png | 1.049 |
| 0.3774 | Blurry | good_19.png | 1.570 |
| 0.3766 | Blurry | good_20.png | 1.498 |
| 0.3953 | Blurry | good_21.png | 1.073 |
| 0.3763 | Blurry | good_22.png | 1.516 |
| 0.3769 | Blurry | good_23.png | 1.576 |
| 0.3952 | Blurry | good_24.png | 1.089 |
| 0.3772 | Blurry | good_25.png | 1.495 |
| 0.3763 | Blurry | good_26.png | 1.522 |
| 0.3951 | Blurry | good_27.png | 1.077 |
| 0.3770 | Blurry | good_28.png | 1.554 |
| 0.3766 | Blurry | good_29.png | 1.565 |
| 0.3959 | Blurry | good_30.png | 1.051 |
| 0.3769 | Blurry | good_31.png | 1.529 |
| 0.3765 | Blurry | good_32.png | 1.515 |
| 0.3955 | Blurry | good_33.png | 1.074 |
| 0.3770 | Blurry | good_34.png | 1.513 |
| 0.3765 | Blurry | good_35.png | 1.528 |
| 0.3952 | Blurry | good_36.png | 1.059 |
| 0.3766 | Blurry | good_37.png | 1.535 |
| 0.3766 | Blurry | good_38.png | 1.516 |
| 0.3955 | Blurry | good_39.png | 1.063 |
| 0.3771 | Blurry | good_40.png | 1.522 |
| 0.3765 | Blurry | good_41.png | 1.556 |
| 0.3955 | Blurry | good_42.png | 1.049 |
| 0.3768 | Blurry | good_43.png | 1.521 |
| 0.3763 | Blurry | good_44.png | 1.512 |
| 0.3952 | Blurry | good_45.png | 1.042 |
| 0.3770 | Blurry | good_46.png | 1.518 |
| 0.3762 | Blurry | good_47.png | 1.555 |
| 0.3958 | Blurry | good_48.png | 1.041 |
| 0.3772 | Blurry | good_49.png | 1.506 |
| 0.3765 | Blurry | good_50.png | 1.530 |
| 0.3955 | Blurry | good_51.png | 1.085 |
| 0.3768 | Blurry | good_52.png | 1.535 |
| 0.3765 | Blurry | good_53.png | 1.513 |
| 0.3957 | Blurry | good_54.png | 1.063 |
| 0.3769 | Blurry | good_55.png | 1.522 |
| 0.3767 | Blurry | good_56.png | 1.544 |
| 0.3954 | Blurry | good_57.png | 1.062 |
| 0.3766 | Blurry | good_58.png | 1.517 |
| 0.3765 | Duplicate | good_59.png | 1.546 |
First 60 of 74 rows.
View data
| Height (px) | File | Width (px) |
|---|---|---|
| 32 | good_00.png | 32 |
| 32 | good_01.png | 40 |
| 40 | good_02.png | 32 |
| 32 | good_03.png | 32 |
| 32 | good_04.png | 40 |
| 40 | good_05.png | 32 |
| 32 | good_06.png | 32 |
| 32 | good_07.png | 40 |
| 40 | good_08.png | 32 |
| 32 | good_09.png | 32 |
| 32 | good_10.png | 40 |
| 40 | good_11.png | 32 |
| 32 | good_12.png | 32 |
| 32 | good_13.png | 40 |
| 40 | good_14.png | 32 |
| 32 | good_15.png | 32 |
| 32 | good_16.png | 40 |
| 40 | good_17.png | 32 |
| 32 | good_18.png | 32 |
| 32 | good_19.png | 40 |
| 40 | good_20.png | 32 |
| 32 | good_21.png | 32 |
| 32 | good_22.png | 40 |
| 40 | good_23.png | 32 |
| 32 | good_24.png | 32 |
| 32 | good_25.png | 40 |
| 40 | good_26.png | 32 |
| 32 | good_27.png | 32 |
| 32 | good_28.png | 40 |
| 40 | good_29.png | 32 |
| 32 | good_30.png | 32 |
| 32 | good_31.png | 40 |
| 40 | good_32.png | 32 |
| 32 | good_33.png | 32 |
| 32 | good_34.png | 40 |
| 40 | good_35.png | 32 |
| 32 | good_36.png | 32 |
| 32 | good_37.png | 40 |
| 40 | good_38.png | 32 |
| 32 | good_39.png | 32 |
| 32 | good_40.png | 40 |
| 40 | good_41.png | 32 |
| 32 | good_42.png | 32 |
| 32 | good_43.png | 40 |
| 40 | good_44.png | 32 |
| 32 | good_45.png | 32 |
| 32 | good_46.png | 40 |
| 40 | good_47.png | 32 |
| 32 | good_48.png | 32 |
| 32 | good_49.png | 40 |
| 40 | good_50.png | 32 |
| 32 | good_51.png | 32 |
| 32 | good_52.png | 40 |
| 40 | good_53.png | 32 |
| 32 | good_54.png | 32 |
| 32 | good_55.png | 40 |
| 40 | good_56.png | 32 |
| 32 | good_57.png | 32 |
| 32 | good_58.png | 40 |
| 40 | good_59.png | 32 |
First 60 of 74 rows.
View data
| Aspect ratio |
|---|
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
| 1 |
| 1.250 |
| 0.8000 |
First 60 of 74 rows.
Assumptions
- Measured on a 256 × 256 copy — Every image was resized to 256 × 256 (stretched) before measuring.
- Sharpness depends on content — Plain images score low without being blurred.
- Similar scenes are not copies — 2 near-duplicate pairs: look at them before removing any.
Flagged images
| Row | File | Flag | Brightness | Sharpness |
|---|---|---|---|---|
| 1 | good_00.png | Blurry | 0.3951 | 1.052 |
| 2 | good_01.png | Blurry | 0.3771 | 1.499 |
| 3 | good_02.png | Blurry | 0.3765 | 1.568 |
| 4 | good_03.png | Blurry | 0.3952 | 1.093 |
| 5 | good_04.png | Blurry | 0.3771 | 1.489 |
| 6 | good_05.png | Blurry | 0.3765 | 1.537 |
| 7 | good_06.png | Blurry | 0.3952 | 1.049 |
| 8 | good_07.png | Blurry | 0.3768 | 1.490 |
| 9 | good_08.png | Blurry | 0.3764 | 1.537 |
| 10 | good_09.png | Blurry | 0.3954 | 1.079 |
| 11 | good_10.png | Blurry | 0.3772 | 1.481 |
| 12 | good_11.png | Blurry | 0.3766 | 1.505 |
| 13 | good_12.png | Blurry | 0.3954 | 1.076 |
| 14 | good_13.png | Blurry | 0.3770 | 1.519 |
| 15 | good_14.png | Blurry | 0.3767 | 1.517 |
| 16 | good_15.png | Blurry | 0.3957 | 1.057 |
| 17 | good_16.png | Blurry | 0.3775 | 1.571 |
| 18 | good_17.png | Blurry | 0.3766 | 1.542 |
| 19 | good_18.png | Blurry | 0.3953 | 1.049 |
| 20 | good_19.png | Blurry | 0.3774 | 1.570 |
| 21 | good_20.png | Blurry | 0.3766 | 1.498 |
| 22 | good_21.png | Blurry | 0.3953 | 1.073 |
| 23 | good_22.png | Blurry | 0.3763 | 1.516 |
| 24 | good_23.png | Blurry | 0.3769 | 1.576 |
| 25 | good_24.png | Blurry | 0.3952 | 1.089 |
| 26 | good_25.png | Blurry | 0.3772 | 1.495 |
| 27 | good_26.png | Blurry | 0.3763 | 1.522 |
| 28 | good_27.png | Blurry | 0.3951 | 1.077 |
| 29 | good_28.png | Blurry | 0.3770 | 1.554 |
| 30 | good_29.png | Blurry | 0.3766 | 1.565 |
| 31 | good_30.png | Blurry | 0.3959 | 1.051 |
| 32 | good_31.png | Blurry | 0.3769 | 1.529 |
| 33 | good_32.png | Blurry | 0.3765 | 1.515 |
| 34 | good_33.png | Blurry | 0.3955 | 1.074 |
| 35 | good_34.png | Blurry | 0.3770 | 1.513 |
| 36 | good_35.png | Blurry | 0.3765 | 1.528 |
| 37 | good_36.png | Blurry | 0.3952 | 1.059 |
| 38 | good_37.png | Blurry | 0.3766 | 1.535 |
| 39 | good_38.png | Blurry | 0.3766 | 1.516 |
| 40 | good_39.png | Blurry | 0.3955 | 1.063 |
First 40 of 50 rows.
Copies and near-duplicates
| Kind | Row | File | Row | Copy | Bits apart | Split | Copy's split |
|---|---|---|---|---|---|---|---|
| identical | 4 | good_03.png | 73 | good_03_copy.png | 0 | train | test |
| near | 6 | good_05.png | 74 | good_05_edit.png | 0 | train | test |
| near | 30 | good_29.png | 60 | good_59.png | 6 | train | test |
Sources on both sides of the split
| Source | Training images | Held-out images |
|---|---|---|
| cam2 | 19 | 5 |
Quality by label
| label | Images | Mean brightness | Mean contrast | Median sharpness | Flagged |
|---|---|---|---|---|---|
| defect | 4 | 0.3721 | 0.1416 | 2.000 | 4 |
| good | 70 | 0.3789 | 0.1465 | 1.513 | 70 |
- 1 rows have no path and are left out.
- 1 files could not be decoded and are left out.
The exact R script · R R version 4.5.1 (2025-06-13)
# Image quality and duplicate audit
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method describe.image_quality 1.0.0 · spec ae37c18b80f5568e
# Dataset: img2_parts (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Images listed in the path column (one decoded 256 x 256 copy per file)
PATH <- "path"
LABEL <- "label"
SPLIT <- "split"
SOURCE <- "source"
WIDTH <- "width"
HEIGHT <- "height"
cols_ <- unique(c(PATH, LABEL, SPLIT, SOURCE, WIDTH, HEIGHT))
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/img2_parts.parquet", col_select = cols_))
if (!nrow(df)) cs_error("CS_E_NO_ROWS")
warnings <- character(0)
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
media <- cs_media_setup(jsonlite::fromJSON("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"image\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"stretch\",\"mode\":\"rgb\",\"normalize\":\"none\",\"size\":[256,256]}}", simplifyVector = FALSE), "target/academy-parity/run-8142/describe.image_quality/parts_split_source_sizes/out-r", df,
"tests/parity/fixtures/img2_parts.parquet")
media_ids <- cs_media_ids(media, df)
text_ <- function(v) { v <- as.character(v); v[!is.na(v) & !nzchar(v)] <- NA_character_; v }
paths_ <- text_(df[[PATH]])
rd_ <- cs_imgc_read(media, media_ids, paths_)
ok <- rd_$ok; n_no_path <- rd_$n_no_path; n_unreadable <- rd_$n_unreadable; X <- rd_$X # X: (n, c, h, w) on 0-1
if (!length(ok)) {
if (n_no_path == nrow(df)) cs_error("CS_E_ALL_MISSING", column = PATH)
# None of the listed files could be decoded.
cs_error("CS_E_INVALID_VALUES", column = PATH, requirement = "an image file that can be decoded", count = n_unreadable)
}
if (n_no_path) warnings <- c(warnings, sprintf("%d rows have no path and are left out.", n_no_path))
if (n_unreadable) warnings <- c(warnings, sprintf("%d files could not be decoded and are left out.", n_unreadable))
n <- length(ok)
# %% Measures and hashes
HASH <- "phash"
DUP <- 6
meas <- vector("list", n)
bits <- list(ahash = matrix(FALSE, n, 64), dhash = matrix(FALSE, n, 64), phash = matrix(FALSE, n, 64))
for (i in seq_len(n)) {
t_ <- array(X[i, , , ], dim(X)[-1])
meas[[i]] <- cs_img_measures(aperm(t_, c(2, 3, 1)) * 255)
hs <- cs_imgh_image(t_)
for (k in names(bits)) bits[[k]][i, ] <- hs[[k]]
}
ids <- media_ids[ok]
files <- basename(paths_[ok])
rows1 <- ok
m_ <- function(key) vapply(meas, function(m) m[[key]], 0)
# %% Copies: identical files (same content hash) and near-duplicates (hash distance)
exact <- cs_imgh_exact_pairs(ids)
exact_group <- cs_imgh_exact_groups(ids)
near_all <- cs_imgh_near_pairs(bits[[HASH]], DUP)
near <- near_all[ids[near_all[, 1]] != ids[near_all[, 2]], , drop = FALSE]
near_group <- cs_imgh_groups(n, near)
sides <- if (!is.null(SPLIT)) cs_imgh_split_side(text_(df[[SPLIT]])[ok]) else rep(NA_integer_, n)
cross_exact <- cs_imgh_cross_split(exact, sides)
cross_near <- cs_imgh_cross_split(near, sides)
held_ <- function(p) length(unique(ifelse(sides[p[, 1]] == 0L, p[, 1], p[, 2])))
sources <- if (!is.null(SOURCE)) text_(df[[SOURCE]])[ok] else rep(NA_character_, n)
across <- if (!is.null(SOURCE) && !is.null(SPLIT)) cs_imgh_groups_across(sources, sides) else character(0)
# %% Flags
DARK <- 0.15; BRIGHT <- 0.85; BLUR <- 100
first_near <- integer(0)
for (j in seq_len(n)) {
g <- as.character(near_group[j])
if (near_group[j] > 0 && is.na(first_near[g])) first_near[g] <- j
}
later_exact <- exact[, 2]
flags <- character(n)
for (j in seq_len(n)) {
m <- meas[[j]]
copy <- (exact_group[j] > 0 && j %in% later_exact) || (near_group[j] > 0 && first_near[[as.character(near_group[j])]] != j)
flags[j] <- if (copy) "Duplicate" else if (m$brightness < DARK) "Dark" else if (m$brightness > BRIGHT) "Bright" else
if (!is.nan(m$sharpness) && m$sharpness < BLUR) "Blurry" else "OK"
}
# %% Artifacts
out <- cs_ml_out_dir("target/academy-parity/run-8142/describe.image_quality/parts_split_source_sizes/out-r")
art <- data.frame(row = as.integer(rows1), media_id = ids, file = files, stringsAsFactors = FALSE)
for (k in c("brightness", "contrast", "colourfulness", "saturation", "sharpness", "entropy", "clipped_dark", "clipped_bright")) art[[if (k == "colourfulness") "colorfulness" else k]] <- m_(k)
for (k in c("ahash", "dhash", "phash")) art[[k]] <- cs_imgh_hex(bits[[k]])
art$exact_group <- as.integer(exact_group)
art$near_group <- as.integer(near_group)
art$flag <- flags
nanoparquet::write_parquet(art, file.path(out, "images.parquet"))
split_of_ <- function(i) if (is.null(SPLIT)) NA_character_ else text_(df[[SPLIT]])[ok[i]]
pair_rows_ <- function(p, kind) {
lapply(seq_len(nrow(p)), function(r) {
i <- p[r, 1]; j <- p[r, 2]
list(kind = kind, row_a = rows1[i], row_b = rows1[j], file_a = files[i], file_b = files[j], distance = as.integer(p[r, 3]),
split_a = split_of_(i), split_b = split_of_(j))
})
}
pair_rows <- c(pair_rows_(exact, "identical"), pair_rows_(near, "near"))
pairs_df <- data.frame(
kind = vapply(pair_rows, function(r) r$kind, ""), row_a = vapply(pair_rows, function(r) as.integer(r$row_a), 0L),
row_b = vapply(pair_rows, function(r) as.integer(r$row_b), 0L), file_a = vapply(pair_rows, function(r) r$file_a, ""),
file_b = vapply(pair_rows, function(r) r$file_b, ""), distance = vapply(pair_rows, function(r) r$distance, 0L),
split_a = vapply(pair_rows, function(r) r$split_a, ""), split_b = vapply(pair_rows, function(r) r$split_b, ""),
stringsAsFactors = FALSE
)
nanoparquet::write_parquet(pairs_df, file.path(out, "pairs.parquet"))
# %% Result
B <- m_("brightness")
S <- m_("sharpness")
if (!is.null(WIDTH) && !is.null(HEIGHT)) {
W <- suppressWarnings(as.numeric(df[[WIDTH]][ok])); H <- suppressWarnings(as.numeric(df[[HEIGHT]][ok]))
good <- is.finite(W) & is.finite(H) & W > 0 & H > 0
} else {
W <- numeric(0); H <- numeric(0); good <- logical(0)
}
sized <- any(good)
nul <- function(x) if (sized) x else NULL
values <- list(
n_rows = nrow(df), n_images = n, n_no_path = n_no_path, n_unreadable = n_unreadable,
brightness_mean = mean(B), brightness_sd = if (n > 1) stats::sd(B) else NULL,
contrast_mean = mean(m_("contrast")), colorfulness_mean = mean(m_("colourfulness")), saturation_mean = mean(m_("saturation")),
sharpness_median = stats::median(S), entropy_mean = mean(m_("entropy")),
n_dark = sum(flags == "Dark"), n_bright = sum(flags == "Bright"), n_blurry = sum(flags == "Blurry"),
n_exact_copies = nrow(exact), n_exact_groups = if (n) max(exact_group) else 0L,
n_near_pairs = nrow(near), n_near_groups = if (n) max(near_group) else 0L, n_in_near_groups = sum(near_group > 0),
n_train = sum(sides == 1L, na.rm = TRUE), n_held_out = sum(sides == 0L, na.rm = TRUE),
n_cross_exact = held_(cross_exact), n_cross_near = held_(cross_near),
n_sources = length(unique(sources[!is.na(sources)])), n_groups_across = length(across),
width_median = nul(stats::median(W[good])), height_median = nul(stats::median(H[good])),
aspect_median = nul(stats::median(W[good] / H[good])), share_portrait = nul(mean(H[good] > W[good])),
megapixels_median = nul(stats::median(W[good] * H[good]) / 1e6),
n_sizes = nul(nrow(unique(data.frame(w = W[good], h = H[good])))),
hash = HASH, threshold = DUP
)
group_rows <- list()
if (!is.null(LABEL)) {
lab_ <- text_(df[[LABEL]])[ok]
lab_[is.na(lab_)] <- "(missing)"
for (lv in sort(unique(lab_), method = "radix")) {
idx <- which(lab_ == lv)
values[[sprintf("group_n[%s]", lv)]] <- length(idx)
values[[sprintf("group_brightness[%s]", lv)]] <- mean(B[idx])
values[[sprintf("group_sharpness[%s]", lv)]] <- stats::median(S[idx])
group_rows[[length(group_rows) + 1L]] <- list(group = lv, n = length(idx), brightness = mean(B[idx]), contrast = mean(m_("contrast")[idx]),
sharpness = stats::median(S[idx]), flagged = sum(flags[idx] != "OK"))
}
}
assumptions <- list(
list(key = "analysis_copy", label = "Measured on a 256 × 256 copy", status = "info",
detail = "Every image was resized to 256 × 256 (stretched) before measuring."),
list(key = "blur_scale", label = "Sharpness depends on content", status = "info",
detail = "Plain images score low without being blurred."),
list(key = "hashes_similar_scenes", label = "Similar scenes are not copies", status = if (nrow(near)) "warn" else "pass",
detail = if (nrow(near)) sprintf("%d near-duplicate pairs: look at them before removing any.", nrow(near)) else "No near-duplicate pairs at this distance.")
)
flagged <- utils::head(which(flags != "OK"), 50L)
pair_cols <- c(list(list(key = "kind", label = "Kind"), list(key = "row_a", label = "Row", type = "integer"), list(key = "file_a", label = "File"),
list(key = "row_b", label = "Row", type = "integer"), list(key = "file_b", label = "Copy"), list(key = "distance", label = "Bits apart", type = "integer")),
if (!is.null(SPLIT)) list(list(key = "split_a", label = "Split"), list(key = "split_b", label = "Copy's split")) else list())
tables <- list(
list(key = "flagged", title = "Flagged images",
columns = list(list(key = "row", label = "Row", type = "integer"), list(key = "file", label = "File"), list(key = "flag", label = "Flag"),
list(key = "brightness", label = "Brightness", type = "number"), list(key = "sharpness", label = "Sharpness", type = "number")),
rows = lapply(flagged, function(j) list(row = rows1[j], file = files[j], flag = flags[j], brightness = meas[[j]]$brightness, sharpness = meas[[j]]$sharpness))),
list(key = "pairs", title = "Copies and near-duplicates", columns = pair_cols,
rows = lapply(utils::head(pair_rows, 200L), function(r) if (is.null(SPLIT)) r[setdiff(names(r), c("split_a", "split_b"))] else r))
)
if (length(across)) {
tables[[length(tables) + 1L]] <- list(key = "across", title = "Sources on both sides of the split",
columns = list(list(key = "source", label = "Source"), list(key = "train", label = "Training images", type = "integer"), list(key = "held_out", label = "Held-out images", type = "integer")),
rows = lapply(utils::head(across, 200L), function(g) list(source = g, train = sum(sources == g & sides == 1L, na.rm = TRUE), held_out = sum(sources == g & sides == 0L, na.rm = TRUE))))
}
if (!is.null(LABEL)) {
tables[[length(tables) + 1L]] <- list(key = "groups", title = paste("Quality by", LABEL),
columns = list(list(key = "group", label = LABEL), list(key = "n", label = "Images", type = "integer"), list(key = "brightness", label = "Mean brightness", type = "number"),
list(key = "contrast", label = "Mean contrast", type = "number"), list(key = "sharpness", label = "Median sharpness", type = "number"), list(key = "flagged", label = "Flagged", type = "integer")),
rows = group_rows)
}
FLAG_LEVELS <- c("OK", "Dark", "Bright", "Blurry", "Duplicate")
charts <- list(cs_chart("quality", "image-quality", "Brightness and sharpness", list(
brightness = cs_col("Brightness (0–1)", B, "numeric"),
sharpness = cs_col("Sharpness (variance of the Laplacian)", S, "numeric"),
flag = cs_col("Flag", flags, "categorical", FLAG_LEVELS),
label = cs_col("File", files, "categorical")
), controls = list(dark = DARK, bright = BRIGHT, blur = BLUR)))
if (sized) {
charts[[length(charts) + 1L]] <- cs_chart("sizes", "image-sizes", "Pixel sizes", list(
width = cs_col("Width (px)", W[good], "numeric"),
height = cs_col("Height (px)", H[good], "numeric"),
label = cs_col("File", files[good], "categorical")
))
charts[[length(charts) + 1L]] <- cs_chart("aspect", "histogram", "Aspect ratios (width ÷ height)", list(x = cs_col("Aspect ratio", W[good] / H[good], "numeric")))
}
cs_publish(list(
title = "Image quality and duplicate audit",
engine = cs_engine_info("codesplashr", "nanoparquet"),
n = n,
summary = sprintf("%d images: %d dark, %d bright, %d blurry; %d identical copies, %d near-duplicate pairs.", n, values$n_dark, values$n_bright, values$n_blurry, nrow(exact), nrow(near)),
statistics = list(
list(key = "n_images", label = "Images read", value = n),
list(key = "brightness_mean", label = "Mean brightness", value = values$brightness_mean),
list(key = "sharpness_median", label = "Median sharpness", value = values$sharpness_median),
list(key = "n_exact_copies", label = "Identical copies", value = nrow(exact)),
list(key = "n_near_pairs", label = "Near-duplicate pairs", value = nrow(near))
),
tables = tables,
assumptions = assumptions,
charts = charts,
values = values,
warnings = as.list(warnings),
artifacts = list(list(key = "images", path = file.path(out, "images.parquet"), format = "parquet"),
list(key = "pairs", path = file.path(out, "pairs.parquet"), format = "parquet"))
))
74 images: 1 dark, 0 bright, 70 blurry; 1 identical copies, 2 near-duplicate pairs.
- Images read
- 74
- Mean brightness
- 0.3786
- Median sharpness
- 1.513
- Identical copies
- 1
- Near-duplicate pairs
- 2
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Measured on a 256 × 256 copy — Every image was resized to 256 × 256 (stretched) before measuring.
- Sharpness depends on content — Plain images score low without being blurred.
- Similar scenes are not copies — 2 near-duplicate pairs: look at them before removing any.
Flagged images
| Row | File | Flag | Brightness | Sharpness |
|---|---|---|---|---|
| 1 | good_00.png | Blurry | 0.3951 | 1.052 |
| 2 | good_01.png | Blurry | 0.3771 | 1.499 |
| 3 | good_02.png | Blurry | 0.3765 | 1.568 |
| 4 | good_03.png | Blurry | 0.3952 | 1.093 |
| 5 | good_04.png | Blurry | 0.3771 | 1.489 |
| 6 | good_05.png | Blurry | 0.3765 | 1.537 |
| 7 | good_06.png | Blurry | 0.3952 | 1.049 |
| 8 | good_07.png | Blurry | 0.3768 | 1.490 |
| 9 | good_08.png | Blurry | 0.3764 | 1.537 |
| 10 | good_09.png | Blurry | 0.3954 | 1.079 |
| 11 | good_10.png | Blurry | 0.3772 | 1.481 |
| 12 | good_11.png | Blurry | 0.3766 | 1.505 |
| 13 | good_12.png | Blurry | 0.3954 | 1.076 |
| 14 | good_13.png | Blurry | 0.3770 | 1.519 |
| 15 | good_14.png | Blurry | 0.3767 | 1.517 |
| 16 | good_15.png | Blurry | 0.3957 | 1.057 |
| 17 | good_16.png | Blurry | 0.3775 | 1.571 |
| 18 | good_17.png | Blurry | 0.3766 | 1.542 |
| 19 | good_18.png | Blurry | 0.3953 | 1.049 |
| 20 | good_19.png | Blurry | 0.3774 | 1.570 |
| 21 | good_20.png | Blurry | 0.3766 | 1.498 |
| 22 | good_21.png | Blurry | 0.3953 | 1.073 |
| 23 | good_22.png | Blurry | 0.3763 | 1.516 |
| 24 | good_23.png | Blurry | 0.3769 | 1.576 |
| 25 | good_24.png | Blurry | 0.3952 | 1.089 |
| 26 | good_25.png | Blurry | 0.3772 | 1.495 |
| 27 | good_26.png | Blurry | 0.3763 | 1.522 |
| 28 | good_27.png | Blurry | 0.3951 | 1.077 |
| 29 | good_28.png | Blurry | 0.3770 | 1.554 |
| 30 | good_29.png | Blurry | 0.3766 | 1.565 |
| 31 | good_30.png | Blurry | 0.3959 | 1.051 |
| 32 | good_31.png | Blurry | 0.3769 | 1.529 |
| 33 | good_32.png | Blurry | 0.3765 | 1.515 |
| 34 | good_33.png | Blurry | 0.3955 | 1.074 |
| 35 | good_34.png | Blurry | 0.3770 | 1.513 |
| 36 | good_35.png | Blurry | 0.3765 | 1.528 |
| 37 | good_36.png | Blurry | 0.3952 | 1.059 |
| 38 | good_37.png | Blurry | 0.3766 | 1.535 |
| 39 | good_38.png | Blurry | 0.3766 | 1.516 |
| 40 | good_39.png | Blurry | 0.3955 | 1.063 |
First 40 of 50 rows.
Copies and near-duplicates
| Kind | Row | File | Row | Copy | Bits apart | Split | Copy's split |
|---|---|---|---|---|---|---|---|
| identical | 4 | good_03.png | 73 | good_03_copy.png | 0 | train | test |
| near | 6 | good_05.png | 74 | good_05_edit.png | 0 | train | test |
| near | 30 | good_29.png | 60 | good_59.png | 6 | train | test |
Sources on both sides of the split
| Source | Training images | Held-out images |
|---|---|---|
| cam2 | 19 | 5 |
Quality by label
| label | Images | Mean brightness | Mean contrast | Median sharpness | Flagged |
|---|---|---|---|---|---|
| defect | 4 | 0.3721 | 0.1416 | 2.000 | 4 |
| good | 70 | 0.3789 | 0.1465 | 1.513 | 70 |
- 1 rows have no path and are left out.
- 1 files could not be decoded and are left out.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Image quality and duplicate audit
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method describe.image_quality 1.0.0 · spec ae37c18b80f5568e
# Dataset: img2_parts (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import os
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash import ml as csml
from codesplash.images import features as fx
from codesplash.images import hashes as hx
# %% Images listed in the path column (one decoded 256 x 256 copy per file)
PATH = "path"
LABEL = "label"
SPLIT = "split"
SOURCE = "source"
WIDTH = "width"
HEIGHT = "height"
_cols = list(dict.fromkeys(c for c in (PATH, LABEL, SPLIT, SOURCE, WIDTH, HEIGHT) if c is not None))
df = pd.read_parquet("tests/parity/fixtures/img2_parts.parquet", columns=_cols)
if not len(df):
cs.cs_error("CS_E_NO_ROWS")
warnings = []
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
import json as _media_json
from codesplash import media as cs_media
media = cs_media.setup(_media_json.loads("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"image\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"stretch\",\"mode\":\"rgb\",\"normalize\":\"none\",\"size\":[256,256]}}"), "target/academy-parity/run-8142/describe.image_quality/parts_split_source_sizes/out-python", df, "tests/parity/fixtures/img2_parts.parquet")
media_ids = cs_media.ids_of(media, df)
def _text(v):
return None if pd.isna(v) else str(v) # None, NaN, pd.NA
from codesplash.images import collection as cimg
ok, n_no_path, n_unreadable, X = cimg.read(media, media_ids, df[PATH].tolist()) # X: float32 (n, c, h, w) on 0–1
if not ok:
if n_no_path == len(df):
cs.cs_error("CS_E_ALL_MISSING", column=PATH)
# None of the listed files could be decoded.
cs.cs_error("CS_E_INVALID_VALUES", column=PATH, requirement="an image file that can be decoded", count=n_unreadable)
if n_no_path:
warnings.append(f"{n_no_path} rows have no path and are left out.")
if n_unreadable:
warnings.append(f"{n_unreadable} files could not be decoded and are left out.")
# %% Measures and hashes
HASH = "phash"
DUP = 6
meas, bits = [], {k: [] for k in hx.KINDS}
for i in range(len(ok)):
t = X[i].astype(np.float64)
meas.append(fx.measures(np.transpose(t, (1, 2, 0)) * 255))
for k, b in hx.image_hashes(t).items():
bits[k].append(b)
bits = {k: np.array(v, dtype=bool).reshape(len(ok), 64) for k, v in bits.items()}
ids = [media_ids[k] for k in ok]
files = [os.path.basename(str(df[PATH].iloc[k])) for k in ok]
rows1 = [k + 1 for k in ok] # 1-based input rows
# %% Copies: identical files (same content hash) and near-duplicates (hash distance)
exact = hx.exact_pairs(ids)
exact_group = hx.exact_groups(ids)
near_all = hx.near_pairs(bits[HASH], DUP)
near = near_all[[ids[i] != ids[j] for i, j, _ in near_all]] if len(near_all) else near_all
near_group = hx.groups_from_pairs(len(ok), near)
sides = [hx.split_side(_text(df[SPLIT].iloc[k])) for k in ok] if SPLIT is not None else [None] * len(ok)
cross_exact = hx.cross_split(exact, sides)
cross_near = hx.cross_split(near, sides)
held = lambda pairs: sorted({int(i) if sides[i] == 0 else int(j) for i, j, _ in pairs})
sources = [_text(df[SOURCE].iloc[k]) for k in ok] if SOURCE is not None else [None] * len(ok)
across = hx.groups_across_splits(sources, sides) if SOURCE is not None and SPLIT is not None else []
# %% Flags
DARK, BRIGHT, BLUR = 0.15, 0.85, 100
first_near = {}
for j, g in enumerate(near_group):
if g and g not in first_near:
first_near[g] = j
later_exact = {int(p[1]) for p in exact}
flags = []
for j, m in enumerate(meas):
copy = (exact_group[j] and j in later_exact) or (near_group[j] and first_near[near_group[j]] != j)
if copy:
f = "Duplicate"
elif m["brightness"] < DARK:
f = "Dark"
elif m["brightness"] > BRIGHT:
f = "Bright"
elif m["sharpness"] == m["sharpness"] and m["sharpness"] < BLUR:
f = "Blurry"
else:
f = "OK"
flags.append(f)
# %% Artifacts
out = csml.out_dir("target/academy-parity/run-8142/describe.image_quality/parts_split_source_sizes/out-python")
art = pd.DataFrame({
"row": np.array(rows1, dtype=np.int64),
"media_id": pd.array(ids, dtype="string"),
"file": pd.array(files, dtype="string"),
**{name: np.array([m[k] for m in meas], dtype=np.float64) for name, k in (("brightness", "brightness"), ("contrast", "contrast"), ("colorfulness", "colourfulness"), ("saturation", "saturation"), ("sharpness", "sharpness"), ("entropy", "entropy"), ("clipped_dark", "clipped_dark"), ("clipped_bright", "clipped_bright"))},
**{k: pd.array(hx.to_hex(bits[k]), dtype="string") for k in hx.KINDS},
"exact_group": np.asarray(exact_group, dtype=np.int64),
"near_group": np.asarray(near_group, dtype=np.int64),
"flag": pd.array(flags, dtype="string"),
})
art.to_parquet(os.path.join(out, "images.parquet"), index=False)
def _pair_rows(pairs, kind):
return [{"kind": kind, "row_a": rows1[int(i)], "row_b": rows1[int(j)], "file_a": files[int(i)], "file_b": files[int(j)],
"distance": int(d), "split_a": None if SPLIT is None else _text(df[SPLIT].iloc[ok[int(i)]]),
"split_b": None if SPLIT is None else _text(df[SPLIT].iloc[ok[int(j)]])} for i, j, d in pairs]
pair_rows = _pair_rows(exact, "identical") + _pair_rows(near, "near")
pairs_df = pd.DataFrame(pair_rows, columns=["kind", "row_a", "row_b", "file_a", "file_b", "distance", "split_a", "split_b"])
for c in ("kind", "file_a", "file_b", "split_a", "split_b"):
pairs_df[c] = pairs_df[c].astype("string")
for c in ("row_a", "row_b", "distance"):
pairs_df[c] = pairs_df[c].astype(np.int64)
pairs_df.to_parquet(os.path.join(out, "pairs.parquet"), index=False)
# %% Result
B = np.array([m["brightness"] for m in meas])
S = np.array([m["sharpness"] for m in meas])
if WIDTH is not None and HEIGHT is not None:
W = pd.to_numeric(df[WIDTH].iloc[ok], errors="coerce").to_numpy(dtype=np.float64)
H = pd.to_numeric(df[HEIGHT].iloc[ok], errors="coerce").to_numpy(dtype=np.float64)
good = np.isfinite(W) & np.isfinite(H) & (W > 0) & (H > 0)
else:
W = H = np.zeros(0)
good = np.zeros(0, dtype=bool)
sized = good.any()
values = {
"n_rows": len(df), "n_images": len(ok), "n_no_path": n_no_path, "n_unreadable": n_unreadable,
"brightness_mean": float(B.mean()), "brightness_sd": float(B.std(ddof=1)) if len(B) > 1 else None,
"contrast_mean": float(np.mean([m["contrast"] for m in meas])),
"colorfulness_mean": float(np.mean([m["colourfulness"] for m in meas])),
"saturation_mean": float(np.mean([m["saturation"] for m in meas])),
"sharpness_median": float(np.median(S)),
"entropy_mean": float(np.mean([m["entropy"] for m in meas])),
"n_dark": flags.count("Dark"), "n_bright": flags.count("Bright"), "n_blurry": flags.count("Blurry"),
"n_exact_copies": len(exact), "n_exact_groups": int(exact_group.max()) if len(exact_group) else 0,
"n_near_pairs": len(near), "n_near_groups": int(near_group.max()) if len(near_group) else 0,
"n_in_near_groups": int(np.sum(near_group > 0)),
"n_train": sum(1 for s in sides if s == 1), "n_held_out": sum(1 for s in sides if s == 0),
"n_cross_exact": len(held(cross_exact)), "n_cross_near": len(held(cross_near)),
"n_sources": len({s for s in sources if s is not None}), "n_groups_across": len(across),
"width_median": float(np.median(W[good])) if sized else None, "height_median": float(np.median(H[good])) if sized else None,
"aspect_median": float(np.median(W[good] / H[good])) if sized else None,
"share_portrait": float(np.mean(H[good] > W[good])) if sized else None,
"megapixels_median": float(np.median(W[good] * H[good]) / 1e6) if sized else None,
"n_sizes": len({(float(w), float(h)) for w, h in zip(W[good], H[good])}) if sized else None,
"hash": HASH, "threshold": DUP,
}
if LABEL is not None:
_lab = ["(missing)" if _text(df[LABEL].iloc[k]) is None else _text(df[LABEL].iloc[k]) for k in ok]
group_rows = []
for lv in sorted(set(_lab)):
idx = [j for j, v in enumerate(_lab) if v == lv]
values[f"group_n[{lv}]"] = len(idx)
values[f"group_brightness[{lv}]"] = float(B[idx].mean())
values[f"group_sharpness[{lv}]"] = float(np.median(S[idx]))
group_rows.append({"group": lv, "n": len(idx), "brightness": float(B[idx].mean()), "contrast": float(np.mean([meas[j]["contrast"] for j in idx])),
"sharpness": float(np.median(S[idx])), "flagged": sum(1 for j in idx if flags[j] != "OK")})
assumptions = [
{"key": "analysis_copy", "label": "Measured on a 256 × 256 copy", "status": "info",
"detail": "Every image was resized to 256 × 256 (stretched) before measuring."},
{"key": "blur_scale", "label": "Sharpness depends on content", "status": "info",
"detail": "Plain images score low without being blurred."},
{"key": "hashes_similar_scenes", "label": "Similar scenes are not copies", "status": "warn" if len(near) else "pass",
"detail": f"{len(near)} near-duplicate pairs: look at them before removing any." if len(near) else "No near-duplicate pairs at this distance."},
]
flagged = [j for j, f in enumerate(flags) if f != "OK"][:50]
tables = [{
"key": "flagged", "title": "Flagged images",
"columns": [{"key": "row", "label": "Row", "type": "integer"}, {"key": "file", "label": "File"}, {"key": "flag", "label": "Flag"},
{"key": "brightness", "label": "Brightness", "type": "number"}, {"key": "sharpness", "label": "Sharpness", "type": "number"}],
"rows": [{"row": rows1[j], "file": files[j], "flag": flags[j], "brightness": meas[j]["brightness"], "sharpness": meas[j]["sharpness"]} for j in flagged],
}, {
"key": "pairs", "title": "Copies and near-duplicates",
"columns": [{"key": "kind", "label": "Kind"}, {"key": "row_a", "label": "Row", "type": "integer"}, {"key": "file_a", "label": "File"},
{"key": "row_b", "label": "Row", "type": "integer"}, {"key": "file_b", "label": "Copy"}, {"key": "distance", "label": "Bits apart", "type": "integer"}]
+ ([{"key": "split_a", "label": "Split"}, {"key": "split_b", "label": "Copy's split"}] if SPLIT is not None else []),
"rows": [{k: v for k, v in r.items() if SPLIT is not None or not k.startswith("split")} for r in pair_rows[:200]],
}]
if across:
tables.append({"key": "across", "title": "Sources on both sides of the split",
"columns": [{"key": "source", "label": "Source"}, {"key": "train", "label": "Training images", "type": "integer"}, {"key": "held_out", "label": "Held-out images", "type": "integer"}],
"rows": [{"source": g, "train": sum(1 for s, sd in zip(sources, sides) if s == g and sd == 1),
"held_out": sum(1 for s, sd in zip(sources, sides) if s == g and sd == 0)} for g in across[:200]]})
if LABEL is not None:
tables.append({"key": "groups", "title": f"Quality by {LABEL}",
"columns": [{"key": "group", "label": LABEL}, {"key": "n", "label": "Images", "type": "integer"}, {"key": "brightness", "label": "Mean brightness", "type": "number"},
{"key": "contrast", "label": "Mean contrast", "type": "number"}, {"key": "sharpness", "label": "Median sharpness", "type": "number"}, {"key": "flagged", "label": "Flagged", "type": "integer"}],
"rows": group_rows})
FLAG_LEVELS = ["OK", "Dark", "Bright", "Blurry", "Duplicate"]
charts = [cs.chart("quality", "image-quality", "Brightness and sharpness", {
"brightness": cs.col("Brightness (0–1)", B, "numeric"),
"sharpness": cs.col("Sharpness (variance of the Laplacian)", S, "numeric"),
"flag": cs.col("Flag", flags, "categorical", FLAG_LEVELS),
"label": cs.col("File", files, "categorical"),
}, controls={"dark": DARK, "bright": BRIGHT, "blur": BLUR})]
if sized:
charts.append(cs.chart("sizes", "image-sizes", "Pixel sizes", {
"width": cs.col("Width (px)", W[good], "numeric"),
"height": cs.col("Height (px)", H[good], "numeric"),
"label": cs.col("File", [f for f, g in zip(files, good) if g], "categorical"),
}))
charts.append(cs.chart("aspect", "histogram", "Aspect ratios (width ÷ height)", {"x": cs.col("Aspect ratio", W[good] / H[good], "numeric")}))
cs.publish({
"title": "Image quality and duplicate audit",
"engine": cs.engine_info("numpy", "pandas"),
"n": len(ok),
"summary": f"{len(ok)} images: {values['n_dark']} dark, {values['n_bright']} bright, {values['n_blurry']} blurry; {len(exact)} identical copies, {len(near)} near-duplicate pairs.",
"statistics": [
{"key": "n_images", "label": "Images read", "value": len(ok)},
{"key": "brightness_mean", "label": "Mean brightness", "value": values["brightness_mean"]},
{"key": "sharpness_median", "label": "Median sharpness", "value": values["sharpness_median"]},
{"key": "n_exact_copies", "label": "Identical copies", "value": len(exact)},
{"key": "n_near_pairs", "label": "Near-duplicate pairs", "value": len(near)},
],
"tables": tables,
"assumptions": assumptions,
"charts": charts,
"values": values,
"warnings": warnings,
"artifacts": [{"key": "images", "path": os.path.join(out, "images.parquet"), "format": "parquet"},
{"key": "pairs", "path": os.path.join(out, "pairs.parquet"), "format": "parquet"}],
})
With a split column, the audit lists held-out images that copy a training image: 2 near copies here. With a source column (camera, patient, session) it also lists sources with images on both sides: 1 camera in the test collection.
View data
| width | height | format |
|---|---|---|
| 256 | 256 | PNG |
| 512 | 512 | PNG |
| 1,920 | 1,080 | PNG |
| 256 | 256 | PNG |
| 1,512 | 2,016 | JPEG |
| 1,500 | 1,000 | JPEG |
| 1,024 | 1,024 | PNG |
| 960 | 540 | PNG |
| 3,000 | 2,000 | JPEG |
| 1,008 | 756 | JPEG |
| 6,000 | 4,000 | JPEG |
| 6,000 | 4,000 | JPEG |
| 512 | 512 | PNG |
| 1,024 | 1,024 | PNG |
| 6,000 | 4,000 | JPEG |
| 6,000 | 4,000 | JPEG |
| 4,032 | 3,024 | JPEG |
| 256 | 256 | PNG |
| 1,500 | 1,000 | JPEG |
| 256 | 256 | PNG |
| 256 | 256 | PNG |
| 1,008 | 756 | JPEG |
| 256 | 256 | PNG |
| 1,512 | 2,016 | JPEG |
| 1,008 | 756 | JPEG |
| 2,016 | 1,512 | JPEG |
| 960 | 540 | PNG |
| 3,024 | 4,032 | JPEG |
| 3,024 | 4,032 | JPEG |
| 1,920 | 1,080 | PNG |
| 1,512 | 2,016 | JPEG |
| 512 | 512 | PNG |
| 1,500 | 1,000 | JPEG |
| 3,024 | 4,032 | JPEG |
| 256 | 256 | PNG |
| 4,032 | 3,024 | JPEG |
| 1,512 | 2,016 | JPEG |
| 512 | 512 | PNG |
| 1,500 | 1,000 | JPEG |
| 960 | 540 | PNG |
| 3,000 | 2,000 | JPEG |
| 256 | 256 | PNG |
| 480 | 270 | PNG |
| 3,024 | 4,032 | JPEG |
| 4,032 | 3,024 | JPEG |
| 1,024 | 1,024 | PNG |
| 256 | 256 | PNG |
| 6,000 | 4,000 | JPEG |
Check yourself
Camera 2 took images in both the training and the test split. Why does that matter for a defect classifier?
Show the answer
Answer: b
Split by source (a grouped split) when the model will meet new cameras, patients or sites.
Insights does this too
CheckpointFor a media collection, Insights runs the same checks on its own: identical files, near-duplicates (on a 32 × 32 copy of up to 20,000 images), copies across the split and sources on both sides, each with Show pairs. The method gives the full tables, the three hashes and the quality measures as a dataset you can filter.
Do it on your own data
In the appAdd a folder with Data → Add image folder…, then open Discover → Images → Image quality and duplicate audit. Pick the split and source columns if the collection has them.
from codesplash.images import hashes as hx
bits = hx.image_hashes(gray_array) # {"ahash": 64 bools, "dhash": …, "phash": …}
print(hx.to_hex(bits["phash"]))
pairs = hx.near_pairs(phash_matrix, 6) # (i, j, bits apart), i < jlibrary(codesplashr)
bits <- cs_imgh_image(gray_matrix) # list(ahash, dhash, phash)
cs_imgh_hex(bits$phash)
pairs <- cs_imgh_near_pairs(phash_matrix, 6) # i, j (1-based), bits apartRecap
Recap- Quality is measured on one 256 × 256 copy per image; small originals come out soft.
- Same content hash means the same file; close perceptual hashes mean the same picture, or a look-alike.
- Remove copies before splitting and split by source, so test scores measure new images.
Concepts in this lesson