Profiling a folder of images
Before images feed a model or a report, check their sizes, exposure, blur, camera metadata and duplicates. Learn what each number measures and where it misleads.
What runs in CodeSplash
You will be able to
- Turn a folder of images into a dataset of file paths and profile it
- Read brightness, sharpness and the duplicate groups, and know their limits
- Spot personal data in photo metadata
A folder becomes a table
ReadImages don't live in a table, so the app makes one. In Discover → Images, Choose a folder… lists every PNG, JPEG and TIFF as one row: its path, file name and subfolder. The images stay where they are.
The profile then opens each file, measures it, and reports one card for the whole collection. The app decodes TIFF files (scans, microscope and lab images) once for it, so Python and R measure the same pixels. Pictures are measured the way they're stored, not turned by their orientation tag.
Make a guess
PredictPredict first
A test folder lists 26 rows, including a damaged PNG, a text file, a missing file and an empty path. How many images will be read?
Make your guess between 0 and 26 images, then reveal.
Reveal
It reads 22; the rest are listed as unreadable, unsupported or missing. The card always says what it left out.
Exposure and blur
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 is the mean luminance from 0 to 1. 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.: strong edges give high values, blur gives low ones.
Plain images (sky, a white backdrop) also score low without being blurred, and small images score lower than large ones. Use the flags to pick files to look at, not to delete.
Sizes and shapes
ExploreView 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 |
Dots on the same dashed ray share a shape. A model that expects one size will resize or crop the rest, so a wide spread here is worth knowing before you train.
Duplicates and metadata
CheckpointA perceptual hashPerceptual hashA 64-bit fingerprint of an image's coarse brightness pattern; resized, re-saved or lightly edited copies get fingerprints a few bits apart. fingerprints the coarse brightness pattern. Copies that were resized or re-saved stay a few bits apart. In the test folder, 3 images fall into near-duplicate groups.
Check yourself
Why remove or group near-duplicates before splitting images into training and test sets?
Show the answer
Answer: b
Leakage between splits inflates test scores. Grouping near-duplicates keeps each group on one side of the split.
Read the card
In the app22 images: median 62 × 48 px; 1 dark, 1 bright, 2 blurry, 3 in near-duplicate groups.
- Images read
- 22
- Mean brightness
- 0.5090
- Median sharpness
- 697.19
- In duplicate groups
- 3
Plots
View data
| Brightness (0–1) | Flag | File | Sharpness (variance of the Laplacian) |
|---|---|---|---|
| 0.5459 | OK | gradient_a.png | 111.35 |
| 0.5459 | Duplicate | gradient_a_copy.png | 111.35 |
| 0.5458 | Duplicate | gradient_a_near.png | 138.60 |
| 0.3877 | OK | gradient_b.png | 111.66 |
| 0.5002 | OK | stripes_fine.png | 22408.52 |
| 0.5002 | OK | stripes_blurred.png | 427.86 |
| 0.5964 | OK | stripes_wide.png | 4403.90 |
| 0.5294 | OK | checker.png | 35891.72 |
| 0.5096 | OK | checker_gray.png | 27468.42 |
| 0.2080 | OK | checker_alpha.png | 966.52 |
| 0.2885 | Blurry | palette.png | 73.680 |
| 0.0469 | Dark | dark.png | 73.171 |
| 0.9604 | Bright | bright.png | 73.887 |
| 0.5020 | Blurry | flat_mid.png | 0 |
| 0.5971 | OK | portrait.png | 201.51 |
| 0.5170 | OK | wide_banner.png | 2909.27 |
| 0.5925 | OK | photo_a.jpg | 1481.37 |
| 0.5011 | OK | photo_b.jpg | 8914.04 |
| 0.4901 | OK | photo_c.jpg | 10461.76 |
| 0.8435 | OK | plain.jpg | 230.68 |
| 0.4903 | OK | gray.jpg | 18698.44 |
| 0.5003 | OK | stripes_fine_copy.jpg | 22509.03 |
View data
| Format | Height (px) | File | Width (px) |
|---|---|---|---|
| PNG | 48 | gradient_a.png | 64 |
| PNG | 48 | gradient_a_copy.png | 64 |
| PNG | 48 | gradient_a_near.png | 64 |
| PNG | 40 | gradient_b.png | 80 |
| PNG | 64 | stripes_fine.png | 64 |
| PNG | 64 | stripes_blurred.png | 64 |
| PNG | 50 | stripes_wide.png | 90 |
| PNG | 60 | checker.png | 60 |
| PNG | 32 | checker_gray.png | 48 |
| PNG | 40 | checker_alpha.png | 40 |
| PNG | 36 | palette.png | 36 |
| PNG | 40 | dark.png | 60 |
| PNG | 40 | bright.png | 60 |
| PNG | 30 | flat_mid.png | 30 |
| PNG | 90 | portrait.png | 40 |
| PNG | 20 | wide_banner.png | 120 |
| JPEG | 48 | photo_a.jpg | 64 |
| JPEG | 56 | photo_b.jpg | 56 |
| JPEG | 48 | photo_c.jpg | 72 |
| JPEG | 40 | plain.jpg | 40 |
| JPEG | 48 | gray.jpg | 48 |
| JPEG | 64 | stripes_fine_copy.jpg | 64 |
View data
| Flag | File | PC 1 | PC 2 |
|---|---|---|---|
| OK | gradient_a.png | 0.7091 | 2.310 |
| Duplicate | gradient_a_copy.png | 0.7091 | 2.310 |
| Duplicate | gradient_a_near.png | 0.7096 | 2.295 |
| OK | gradient_b.png | −2.834 | 0.6196 |
| OK | stripes_fine.png | −0.0566 | −1.913 |
| OK | stripes_blurred.png | −0.1064 | −1.341 |
| OK | stripes_wide.png | 1.954 | 0.8558 |
| OK | checker.png | 0.6090 | −1.846 |
| OK | checker_gray.png | 0.1656 | −1.966 |
| OK | checker_alpha.png | −6.833 | 0.3521 |
| Blurry | palette.png | −5.269 | 2.574 |
| Dark | dark.png | −10.389 | −1.554 |
| Bright | bright.png | 10.204 | −0.4908 |
| Blurry | flat_mid.png | −0.1527 | −1.524 |
| OK | portrait.png | 2.244 | 2.898 |
| OK | wide_banner.png | −0.3354 | 0.6315 |
| OK | photo_a.jpg | 1.766 | 1.773 |
| OK | photo_b.jpg | −0.2190 | −0.4322 |
| OK | photo_c.jpg | −0.2570 | −0.5075 |
| OK | plain.jpg | 7.662 | −1.198 |
| OK | gray.jpg | −0.2377 | −1.765 |
| OK | stripes_fine_copy.jpg | −0.0436 | −2.080 |
Assumptions
- PNG, JPEG and TIFF — 1 listed files are not PNG, JPEG or a readable kind of TIFF.
- Sharpness depends on size and content — Sharpness is measured at most 512 pixels on the long side; plain images score low without being blurred.
- Personal data in metadata — 1 images carry GPS location data (coordinates are not read).
Flagged images
| File | Flag | Brightness | Sharpness | Duplicate group |
|---|---|---|---|---|
| gradient_a_copy.png | Duplicate | 0.5459 | 111.35 | 1 |
| gradient_a_near.png | Duplicate | 0.5458 | 138.60 | 1 |
| palette.png | Blurry | 0.2885 | 73.680 | 0 |
| dark.png | Dark | 0.0469 | 73.171 | 0 |
| bright.png | Bright | 0.9604 | 73.887 | 0 |
| flat_mid.png | Blurry | 0.5020 | 0 | 0 |
Cameras (EXIF)
| Make and model | Images |
|---|---|
| Fixturecam FX-100 | 1 |
| Fixturecam FX-200 | 1 |
| Othercam O-1 | 1 |
- 1 rows have no path and are left out.
- 1 rows point to files that do not exist and are left out.
- 1 rows are not PNG, JPEG or a readable kind of TIFF and are left out.
- 1 rows could not be decoded and are left out.
The exact R script · R R version 4.5.1 (2025-06-13)
# Image collection profile (size, color, sharpness, duplicates)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method describe.images 1.1.0 · spec bcdfced43aa2ed60
# Dataset: ml_images (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
PATH <- "path"
LABEL <- NULL
FOLDER <- path.expand("")
DATA_DIR <- dirname(normalizePath("tests/parity/fixtures/ml_images.parquet", mustWork = FALSE))
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ml_images.parquet", col_select = c(PATH, LABEL)))
# %% 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\":\"original\",\"formats\":[\"tiff\"],\"mode\":\"rgb\",\"normalize\":\"none\",\"orientation\":\"stored\",\"size\":[224,224]}}", simplifyVector = FALSE), "target/academy-parity/run-8142/describe.images/folder_defaults/out-r", df,
"tests/parity/fixtures/ml_images.parquet")
media_ids <- cs_media_ids(media, df)
MAX_SIDE <- 512
warnings <- list()
status <- character(0); info <- list(); feats <- list(); hashes <- list()
nz <- function(x) !is.null(x) && !is.na(x) && nzchar(x)
for (i in seq_len(nrow(df))) {
path <- cs_img_resolve(as.character(df[[PATH]][i]), FOLDER, DATA_DIR)
if (is.na(path)) { status <- c(status, "no path"); info[[i]] <- list(row = i - 1L); next }
r <- cs_img_read(path)
if (r$status == "unsupported" && cs_img_is_tiff(path)) # TIFF: decoded by the host
r <- cs_img_tiff_read(path, r, media, if (is.null(media_ids)) NA_character_ else media_ids[i])
status <- c(status, r$status)
rec <- list(row = i - 1L, path = path, file = basename(path), format = r$format, bytes = r$bytes, md5 = r$md5)
if (r$status == "ok") {
small <- cs_img_fit(r$rgb, MAX_SIDE)
m <- cs_img_measures(small)
h <- cs_img_phash(cs_img_luma(small))
rec <- c(rec, list(width = r$width, height = r$height, alpha = r$alpha, phash = cs_img_hex(h)), m,
if (identical(r$format, "TIFF")) cs_img_tiff_exif(path) else cs_img_exif(path))
feats[[length(feats) + 1]] <- c(m$brightness, m$contrast, m$mean_r, m$mean_g, m$mean_b, m$colourfulness, m$saturation,
if (is.nan(m$sharpness)) NA else log1p(m$sharpness), m$entropy, cs_img_thumb(small))
hashes[[length(hashes) + 1]] <- h
}
info[[i]] <- rec
}
ok <- which(status == "ok")
if (!length(ok)) {
if (!length(status)) cs_error("CS_E_NO_ROWS")
if (all(status == "no path")) cs_error("CS_E_ALL_MISSING", column = PATH)
# None of the listed files could be read (missing, not PNG, JPEG or TIFF, or not decodable).
cs_error("CS_E_INVALID_VALUES", column = PATH, requirement = "a PNG, JPEG or TIFF file that exists",
count = sum(status != "no path"))
}
for (pair in list(c("no path", "have no path"), c("missing", "point to files that do not exist"), c("unsupported", "are not PNG, JPEG or a readable kind of TIFF"), c("unreadable", "could not be decoded"))) {
k <- sum(status == pair[1])
if (k) warnings <- c(warnings, sprintf("%d rows %s and are left out.", k, pair[2]))
}
img <- info[ok]
# %% Duplicates: perceptual-hash groups and identical files
DUP <- 6
groups <- cs_img_dup_groups(hashes, DUP)
md5s <- vapply(img, function(r) r$md5, "")
exact <- duplicated(md5s)
first_in_group <- vapply(seq_along(groups), function(j) groups[j] > 0 && match(groups[j], groups) == j, TRUE)
# %% Map: PCA of the classic features
F <- do.call(rbind, feats)
for (c in seq_len(ncol(F))) F[is.na(F[, c]), c] <- mean(F[, c], na.rm = TRUE)
EMBED_LABEL <- "Classic features"
mp <- if (nrow(F) >= 2) cs_img_classic_map(F) else list(Y = matrix(0, nrow(F), 2), shares = c(NaN, NaN))
Y <- mp$Y
# %% Flags
DARK <- 0.15; BRIGHT <- 0.85; BLUR <- 100
flags <- vapply(seq_along(img), function(j) {
r <- img[[j]]
if (exact[j] || (groups[j] > 0 && !first_in_group[j])) "Duplicate"
else if (r$brightness < DARK) "Dark"
else if (r$brightness > BRIGHT) "Bright"
else if (!is.nan(r$sharpness) && r$sharpness < BLUR) "Blurry" # after exposure: very dark or bright frames have little detail anyway
else "OK"
}, "")
for (j in seq_along(img)) img[[j]] <- c(img[[j]], list(dup_group = groups[j], exact_duplicate = exact[j], flag = flags[j], map_x = Y[j, 1], map_y = Y[j, 2]))
# %% Artifacts
out <- cs_ml_out_dir("target/academy-parity/run-8142/describe.images/folder_defaults/out-r")
get <- function(field, type) {
v <- lapply(img, function(r) if (is.null(r[[field]])) NA else r[[field]])
switch(type, chr = vapply(v, function(x) if (is.na(x)) NA_character_ else as.character(x), ""),
num = vapply(v, function(x) as.numeric(x), 0), int = vapply(v, function(x) as.integer(x), 0L),
lgl = vapply(v, function(x) as.logical(x), TRUE))
}
art <- data.frame(row = get("row", "int"), path = get("path", "chr"), file = get("file", "chr"), format = get("format", "chr"),
bytes = get("bytes", "num"), md5 = get("md5", "chr"), width = get("width", "int"), height = get("height", "int"),
alpha = get("alpha", "lgl"), stringsAsFactors = FALSE)
for (f in c("brightness", "contrast", "mean_r", "mean_g", "mean_b", "colourfulness", "saturation", "sharpness", "entropy", "clipped_dark", "clipped_bright")) art[[f]] <- get(f, "num")
art$phash <- get("phash", "chr"); art$dup_group <- get("dup_group", "int"); art$exact_duplicate <- get("exact_duplicate", "lgl"); art$flag <- get("flag", "chr")
art$make <- get("make", "chr"); art$model <- get("model", "chr"); art$datetime <- get("datetime", "chr")
art$orientation <- get("orientation", "int"); art$exposure <- get("exposure", "num"); art$fnumber <- get("fnumber", "num")
art$iso <- get("iso", "int"); art$focal <- get("focal", "num"); art$gps <- get("gps", "lgl"); art$map_x <- get("map_x", "num"); art$map_y <- get("map_y", "num")
nanoparquet::write_parquet(art, file.path(out, "images.parquet"))
# %% Result
W <- as.numeric(art$width); H <- as.numeric(art$height); B <- art$brightness; S <- art$sharpness
values <- list(
n_rows = nrow(df), n_images = length(img), n_no_path = sum(status == "no path"), n_missing = sum(status == "missing"),
n_unsupported = sum(status == "unsupported"), n_unreadable = sum(status == "unreadable"),
n_png = sum(art$format == "PNG"), n_jpeg = sum(art$format == "JPEG"), n_alpha = sum(art$alpha), bytes_total = sum(art$bytes),
width_min = min(W), width_median = stats::median(W), width_max = max(W),
height_min = min(H), height_median = stats::median(H), height_max = max(H),
megapixels_median = stats::median(W * H) / 1e6, aspect_median = stats::median(W / H),
share_portrait = mean(H > W), n_sizes = nrow(unique(data.frame(W, H))),
brightness_mean = mean(B), brightness_sd = if (length(B) > 1) stats::sd(B) else NULL,
contrast_mean = mean(art$contrast), colourfulness_mean = mean(art$colourfulness), saturation_mean = mean(art$saturation),
sharpness_median = if (any(is.finite(S))) stats::median(S[is.finite(S)]) else NULL,
entropy_mean = mean(art$entropy),
n_dark = sum(flags == "Dark"), n_bright = sum(flags == "Bright"), n_blurry = sum(flags == "Blurry"),
n_exif = sum(vapply(img, function(r) nz(r$make) || nz(r$model) || nz(r$datetime), TRUE)),
n_gps = sum(vapply(img, function(r) isTRUE(r$gps), TRUE)),
n_dup_groups = if (length(groups)) max(groups) else 0L, n_in_dup_groups = sum(groups > 0), n_exact_dups = sum(exact),
map_share_1 = mp$shares[1], map_share_2 = mp$shares[2], embedding = EMBED_LABEL
)
n_tiff <- sum(art$format == "TIFF", na.rm = TRUE)
if (n_tiff > 0) values$n_tiff <- n_tiff # only when TIFF files were read, so results without them keep their keys
cam_names <- vapply(img, function(r) {
parts <- c(if (nz(r$make)) r$make, if (nz(r$model)) r$model)
if (length(parts)) paste(parts, collapse = " ") else NA_character_
}, "")
cams <- table(cam_names[!is.na(cam_names)])
if (length(cams)) cams <- cams[order(names(cams), method = "radix")] # no camera data: an empty table has no names
for (key in names(cams)) values[[sprintf("camera[%s]", key)]] <- as.integer(cams[[key]])
assumptions <- list(
list(key = "formats", label = "PNG, JPEG and TIFF", status = if (values$n_unsupported) "warn" else "pass",
detail = if (values$n_unsupported) sprintf("%d listed files are not PNG, JPEG or a readable kind of TIFF.", values$n_unsupported) else "Every readable file is PNG, JPEG or TIFF."),
list(key = "blur_scale", label = "Sharpness depends on size and content", status = "info",
detail = sprintf("Sharpness is measured at most %d pixels on the long side; plain images score low without being blurred.", MAX_SIDE)),
list(key = "personal_data", label = "Personal data in metadata", status = if (values$n_gps) "warn" else "pass",
detail = if (values$n_gps) sprintf("%d images carry GPS location data (coordinates are not read).", values$n_gps) else "No image carries GPS data.")
)
flagged <- utils::head(which(flags != "OK"), 50)
tables <- list(list(
key = "flagged", title = "Flagged images",
columns = list(list(key = "file", label = "File"), list(key = "flag", label = "Flag"), list(key = "brightness", label = "Brightness", type = "number"),
list(key = "sharpness", label = "Sharpness", type = "number"), list(key = "dup_group", label = "Duplicate group", type = "integer")),
rows = lapply(flagged, function(j) list(file = art$file[j], flag = flags[j], brightness = art$brightness[j], sharpness = art$sharpness[j], dup_group = art$dup_group[j]))
))
if (length(cams)) tables[[2]] <- list(key = "cameras", title = "Cameras (EXIF)",
columns = list(list(key = "camera", label = "Make and model"), list(key = "images", label = "Images", type = "integer")),
rows = lapply(names(cams), function(k) list(camera = k, images = as.integer(cams[[k]]))))
FLAG_LEVELS <- c("OK", "Dark", "Bright", "Blurry", "Duplicate")
if (!is.null(LABEL)) {
lab <- df[[LABEL]][art$row + 1L]
groups_col <- ifelse(is.na(lab), "(missing)", as.character(lab)); group_title <- LABEL
} else {
groups_col <- flags; group_title <- "Flag"
}
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)", ifelse(is.nan(S), 0, S), "numeric"),
flag = cs_col("Flag", flags, "categorical", FLAG_LEVELS),
label = cs_col("File", art$file, "categorical")
), controls = list(dark = DARK, bright = BRIGHT, blur = BLUR)),
cs_chart("sizes", "image-sizes", "Pixel sizes", list(
width = cs_col("Width (px)", W, "numeric"), height = cs_col("Height (px)", H, "numeric"),
group = cs_col("Format", art$format, "categorical"), label = cs_col("File", art$file, "categorical")
)),
cs_chart("map", "cluster-scatter", sprintf("Images by similarity (%s)", tolower(EMBED_LABEL)), list(
x = cs_col("PC 1", Y[, 1], "numeric"), y = cs_col("PC 2", Y[, 2], "numeric"),
cluster = cs_col(group_title, groups_col, "categorical"), label = cs_col("File", art$file, "categorical")
))
)
cs_publish(list(
title = "Image collection profile (size, color, sharpness, duplicates)",
engine = cs_engine_info("png", "jpeg", "codesplashr", "nanoparquet"),
n = length(img),
summary = sprintf("%d images: median %d × %d px; %d dark, %d bright, %d blurry, %d in near-duplicate groups.",
length(img), as.integer(values$width_median), as.integer(values$height_median), values$n_dark, values$n_bright, values$n_blurry, values$n_in_dup_groups),
statistics = list(
list(key = "n_images", label = "Images read", value = length(img)),
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_in_dup_groups", label = "In duplicate groups", value = values$n_in_dup_groups)
),
tables = tables,
assumptions = assumptions,
charts = charts,
values = values,
warnings = warnings,
artifacts = list(list(key = "images", path = file.path(out, "images.parquet"), format = "parquet"))
))
22 images: median 62 × 48 px; 1 dark, 1 bright, 2 blurry, 3 in near-duplicate groups.
- Images read
- 22
- Mean brightness
- 0.5090
- Median sharpness
- 697.19
- In duplicate groups
- 3
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- PNG, JPEG and TIFF — 1 listed files are not PNG, JPEG or a readable kind of TIFF.
- Sharpness depends on size and content — Sharpness is measured at most 512 pixels on the long side; plain images score low without being blurred.
- Personal data in metadata — 1 images carry GPS location data (coordinates are not read).
Flagged images
| File | Flag | Brightness | Sharpness | Duplicate group |
|---|---|---|---|---|
| gradient_a_copy.png | Duplicate | 0.5459 | 111.35 | 1 |
| gradient_a_near.png | Duplicate | 0.5458 | 138.60 | 1 |
| palette.png | Blurry | 0.2885 | 73.680 | 0 |
| dark.png | Dark | 0.0469 | 73.171 | 0 |
| bright.png | Bright | 0.9604 | 73.887 | 0 |
| flat_mid.png | Blurry | 0.5020 | 0 | 0 |
Cameras (EXIF)
| Make and model | Images |
|---|---|
| Fixturecam FX-100 | 1 |
| Fixturecam FX-200 | 1 |
| Othercam O-1 | 1 |
- 1 rows have no path and are left out.
- 1 rows point to files that do not exist and are left out.
- 1 rows are not PNG, JPEG or a readable kind of TIFF and are left out.
- 1 rows 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 collection profile (size, color, sharpness, duplicates)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method describe.images 1.1.0 · spec bcdfced43aa2ed60
# Dataset: ml_images (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 tiff as fxt
# %% Images listed in the path column
PATH = "path"
LABEL = None
FOLDER = os.path.expanduser("")
DATA_DIR = os.path.dirname(os.path.abspath("tests/parity/fixtures/ml_images.parquet"))
df = pd.read_parquet("tests/parity/fixtures/ml_images.parquet", columns=[PATH] if LABEL is None else [PATH, LABEL])
# %% 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\":\"original\",\"formats\":[\"tiff\"],\"mode\":\"rgb\",\"normalize\":\"none\",\"orientation\":\"stored\",\"size\":[224,224]}}"), "target/academy-parity/run-8142/describe.images/folder_defaults/out-python", df, "tests/parity/fixtures/ml_images.parquet")
media_ids = cs_media.ids_of(media, df)
MAX_SIDE = 512
warnings = []
status, info, feats, hashes, thumbs, rgbs = [], [], [], [], [], []
for i, p in enumerate(df[PATH].tolist()):
path = fx.resolve(p, FOLDER, DATA_DIR)
if path is None:
status.append("no path")
info.append({"row": i, "path": None})
continue
r = fx.read(path)
if r["status"] == "unsupported" and fxt.is_tiff(path):
r = fxt.read(path, r, media, media_ids[i] if media_ids else None) # TIFF: decoded by the host
status.append(r["status"])
rec = {"row": i, "path": path, "file": os.path.basename(path), "format": r.get("format"), "bytes": r.get("bytes"), "md5": r.get("md5")}
if r["status"] == "ok":
small = fx.fit(r["rgb"], MAX_SIDE)
m = fx.measures(small)
h = fx.phash(fx.luma(small))
rec.update(width=r["width"], height=r["height"], alpha=r["alpha"], phash=fx.hex_bits(h), **m,
**(fxt.exif(path) if r["format"] == "TIFF" else fx.exif(path)))
feats.append([m["brightness"], m["contrast"], m["mean_r"], m["mean_g"], m["mean_b"], m["colourfulness"], m["saturation"],
np.log1p(m["sharpness"]) if m["sharpness"] == m["sharpness"] else np.nan, m["entropy"], *fx.thumb(small)])
hashes.append(h)
rgbs.append(r["rgb"] if False else None)
info.append(rec)
ok = [k for k, s in enumerate(status) if s == "ok"]
if not ok:
if not status:
cs.cs_error("CS_E_NO_ROWS")
if all(s == "no path" for s in status):
cs.cs_error("CS_E_ALL_MISSING", column=PATH)
# None of the listed files could be read (missing, not PNG, JPEG or TIFF, or not decodable).
cs.cs_error("CS_E_INVALID_VALUES", column=PATH, requirement="a PNG, JPEG or TIFF file that exists",
count=sum(1 for s in status if s != "no path"))
for s, what in (("no path", "have no path"), ("missing", "point to files that do not exist"), ("unsupported", "are not PNG, JPEG or a readable kind of TIFF"), ("unreadable", "could not be decoded")):
k = status.count(s)
if k:
warnings.append(f"{k} rows {what} and are left out.")
img = [info[k] for k in ok]
# %% Duplicates: perceptual-hash groups and identical files
DUP = 6
groups = fx.dup_groups(hashes, DUP)
seen_md5, exact = set(), []
for rec in img:
exact.append(rec["md5"] in seen_md5)
seen_md5.add(rec["md5"])
first_in_group = {}
for j, g in enumerate(groups):
if g and g not in first_in_group:
first_in_group[g] = j
# %% Map: PCA of the classic features
F = np.array(feats, dtype=float)
col_mean = np.nanmean(F, axis=0)
F = np.where(np.isnan(F), col_mean, F)
EMBED_LABEL = "Classic features"
Y, map_shares = fx.classic_map(F) if len(F) >= 2 else (np.zeros((len(F), 2)), [float("nan"), float("nan")])
# %% Flags
DARK, BRIGHT, BLUR = 0.15, 0.85, 100
flags = []
for j, rec in enumerate(img):
if exact[j] or (groups[j] and first_in_group[groups[j]] != j):
f = "Duplicate"
elif rec["brightness"] < DARK:
f = "Dark"
elif rec["brightness"] > BRIGHT:
f = "Bright"
elif rec["sharpness"] == rec["sharpness"] and rec["sharpness"] < BLUR:
f = "Blurry" # after exposure: very dark or bright frames have little detail anyway
else:
f = "OK"
flags.append(f)
rec.update(dup_group=int(groups[j]), exact_duplicate=bool(exact[j]), flag=f, map_x=float(Y[j, 0]), map_y=float(Y[j, 1]))
# %% Artifacts
out = csml.out_dir("target/academy-parity/run-8142/describe.images/folder_defaults/out-python")
cols = ["row", "path", "file", "format", "bytes", "md5", "width", "height", "alpha", "brightness", "contrast", "mean_r", "mean_g", "mean_b",
"colourfulness", "saturation", "sharpness", "entropy", "clipped_dark", "clipped_bright", "phash", "dup_group", "exact_duplicate", "flag",
"make", "model", "datetime", "orientation", "exposure", "fnumber", "iso", "focal", "gps", "map_x", "map_y"]
art = pd.DataFrame([{c: rec.get(c) for c in cols} for rec in img], columns=cols)
for c in ("make", "model", "datetime", "phash", "flag", "format", "file", "path", "md5"):
art[c] = art[c].astype("string")
for c in ("orientation", "iso"):
art[c] = pd.array([None if pd.isna(v) else int(v) for v in art[c]], dtype="Int64")
for c in ("exposure", "fnumber", "focal"):
art[c] = pd.to_numeric(art[c], errors="coerce").astype("float64")
art["gps"] = art["gps"].astype("boolean")
art.to_parquet(os.path.join(out, "images.parquet"), index=False)
# %% Result
W = np.array([r["width"] for r in img], dtype=float)
H = np.array([r["height"] for r in img], dtype=float)
B = np.array([r["brightness"] for r in img])
S = np.array([r["sharpness"] for r in img])
values = {
"n_rows": len(df), "n_images": len(img), "n_no_path": status.count("no path"), "n_missing": status.count("missing"),
"n_unsupported": status.count("unsupported"), "n_unreadable": status.count("unreadable"),
"n_png": sum(r["format"] == "PNG" for r in img), "n_jpeg": sum(r["format"] == "JPEG" for r in img),
"n_alpha": sum(bool(r["alpha"]) for r in img), "bytes_total": int(sum(r["bytes"] for r in img)),
"width_min": float(W.min()), "width_median": float(np.median(W)), "width_max": float(W.max()),
"height_min": float(H.min()), "height_median": float(np.median(H)), "height_max": float(H.max()),
"megapixels_median": float(np.median(W * H) / 1e6), "aspect_median": float(np.median(W / H)),
"share_portrait": float(np.mean(H > W)), "n_sizes": len({(int(w), int(h)) for w, h in zip(W, H)}),
"brightness_mean": float(B.mean()), "brightness_sd": float(B.std(ddof=1)) if len(B) > 1 else None,
"contrast_mean": float(np.mean([r["contrast"] for r in img])),
"colourfulness_mean": float(np.mean([r["colourfulness"] for r in img])),
"saturation_mean": float(np.mean([r["saturation"] for r in img])),
"sharpness_median": float(np.nanmedian(S)) if np.isfinite(S).any() else None,
"entropy_mean": float(np.mean([r["entropy"] for r in img])),
"n_dark": flags.count("Dark"), "n_bright": flags.count("Bright"), "n_blurry": flags.count("Blurry"),
"n_exif": sum(1 for r in img if r.get("make") or r.get("model") or r.get("datetime")),
"n_gps": sum(1 for r in img if r.get("gps")),
"n_dup_groups": int(groups.max()) if len(groups) else 0, "n_in_dup_groups": int(np.sum(groups > 0)),
"n_exact_dups": int(sum(exact)),
"map_share_1": map_shares[0], "map_share_2": map_shares[1], "embedding": EMBED_LABEL,
}
n_tiff = sum(r["format"] == "TIFF" for r in img)
if n_tiff:
values["n_tiff"] = n_tiff # only when TIFF files were read, so results without them keep their keys
cams: dict[str, int] = {}
for r in img:
if r.get("make") or r.get("model"):
key = " ".join(x for x in (r.get("make"), r.get("model")) if x)
cams[key] = cams.get(key, 0) + 1
for key, k in sorted(cams.items()):
values[f"camera[{key}]"] = k
assumptions = [
{"key": "formats", "label": "PNG, JPEG and TIFF", "status": "warn" if values["n_unsupported"] else "pass",
"detail": f"{values['n_unsupported']} listed files are not PNG, JPEG or a readable kind of TIFF." if values["n_unsupported"] else "Every readable file is PNG, JPEG or TIFF."},
{"key": "blur_scale", "label": "Sharpness depends on size and content", "status": "info",
"detail": f"Sharpness is measured at most {MAX_SIDE} pixels on the long side; plain images score low without being blurred."},
{"key": "personal_data", "label": "Personal data in metadata", "status": "warn" if values["n_gps"] else "pass",
"detail": f"{values['n_gps']} images carry GPS location data (coordinates are not read)." if values["n_gps"] else "No image carries GPS data."},
]
flagged = [r for r in img if r["flag"] != "OK"][:50]
tables = [{
"key": "flagged", "title": "Flagged images",
"columns": [{"key": "file", "label": "File"}, {"key": "flag", "label": "Flag"}, {"key": "brightness", "label": "Brightness", "type": "number"},
{"key": "sharpness", "label": "Sharpness", "type": "number"}, {"key": "dup_group", "label": "Duplicate group", "type": "integer"}],
"rows": [{k: r.get(k) for k in ("file", "flag", "brightness", "sharpness", "dup_group")} for r in flagged],
}]
if cams:
tables.append({"key": "cameras", "title": "Cameras (EXIF)", "columns": [{"key": "camera", "label": "Make and model"}, {"key": "images", "label": "Images", "type": "integer"}],
"rows": [{"camera": key, "images": k} for key, k in sorted(cams.items())]})
FLAG_LEVELS = ["OK", "Dark", "Bright", "Blurry", "Duplicate"]
if LABEL is not None:
lab = df[LABEL].iloc[[r["row"] for r in img]]
groups_col = ["(missing)" if pd.isna(v) else str(v) for v in lab]
group_title = LABEL
else:
groups_col, group_title = flags, "Flag"
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)", np.nan_to_num(S, nan=0.0), "numeric"),
"flag": cs.col("Flag", flags, "categorical", FLAG_LEVELS),
"label": cs.col("File", [r["file"] for r in img], "categorical"),
}, controls={"dark": DARK, "bright": BRIGHT, "blur": BLUR}),
cs.chart("sizes", "image-sizes", "Pixel sizes", {
"width": cs.col("Width (px)", W, "numeric"),
"height": cs.col("Height (px)", H, "numeric"),
"group": cs.col("Format", [r["format"] for r in img], "categorical"),
"label": cs.col("File", [r["file"] for r in img], "categorical"),
}),
cs.chart("map", "cluster-scatter", f"Images by similarity ({EMBED_LABEL.lower()})", {
"x": cs.col("PC 1", Y[:, 0], "numeric"),
"y": cs.col("PC 2", Y[:, 1], "numeric"),
"cluster": cs.col(group_title, groups_col, "categorical"),
"label": cs.col("File", [r["file"] for r in img], "categorical"),
}),
]
cs.publish({
"title": "Image collection profile (size, color, sharpness, duplicates)",
"engine": cs.engine_info("pillow", "numpy", "pandas"),
"n": len(img),
"summary": f"{len(img)} images: median {int(values['width_median'])} × {int(values['height_median'])} px; {values['n_dark']} dark, {values['n_bright']} bright, {values['n_blurry']} blurry, {values['n_in_dup_groups']} in near-duplicate groups.",
"statistics": [
{"key": "n_images", "label": "Images read", "value": len(img)},
{"key": "brightness_mean", "label": "Mean brightness", "value": values["brightness_mean"]},
{"key": "sharpness_median", "label": "Median sharpness", "value": values["sharpness_median"]},
{"key": "n_in_dup_groups", "label": "In duplicate groups", "value": values["n_in_dup_groups"]},
],
"tables": tables,
"assumptions": assumptions,
"charts": charts,
"values": values,
"warnings": warnings,
"artifacts": [{"key": "images", "path": os.path.join(out, "images.parquet"), "format": "parquet"}],
})
EXIFEXIF metadataData a camera stores inside a photo: make, model, date taken, exposure, orientation and sometimes GPS location. gives the camera, the date and sometimes a GPS location. The card counts 1 images with GPS data but never reads the coordinates out.
Check yourself
Some photos carry GPS data. What's the sensible step before you share them?
Show the answer
Answer: b
A location can identify a home or a routine. Removing metadata from shared copies keeps the pictures and drops the personal data.
Do it on your own data
In the appChoose Images in Discover, then Choose a folder…. Open Image collection profile when the dataset appears. A pretrained map (MobileNetV3, about 10 MB, Python only) is optional and asks before downloading.
from codesplash.images import features as fx
r = fx.read("photos/IMG_0001.jpg")
small = fx.fit(r["rgb"], 512) # area-averaged copy, long side ≤ 512 px
print(fx.measures(small)["sharpness"], fx.hex_bits(fx.phash(fx.luma(small))))
print(fx.exif("photos/IMG_0001.jpg")) # GPS only as present or absentlibrary(codesplashr)
r <- cs_img_read("photos/IMG_0001.jpg")
small <- cs_img_fit(r$rgb, 512)
cs_img_measures(small)$sharpness
cs_img_hex(cs_img_phash(cs_img_luma(small)))
cs_img_exif("photos/IMG_0001.jpg")Recap
Recap- A folder becomes a dataset of file paths; the profile reads PNG, JPEG and TIFF and lists what it skipped.
- Brightness and sharpness flag files to look at; plain or small images score low without being bad.
- Group near-duplicates before splitting, and treat photo metadata as personal data.
Concepts in this lesson