What it does
reproimage helps check the figures of a manuscript, a thesis or a data set before publication or during a reproducibility audit. It finds three kinds of relation between images:
| Category | Rule |
|---|---|
| Identical files | Same SHA-256 of the file bytes |
| Identical pixels | Same SHA-256 of the decoded pixels, for example the same image saved as PNG and TIFF |
| Visually similar | Difference and perceptual hashes within a distance threshold, in any of eight orientations |
These are visual relations, never evidence of misconduct. A similar pair may be a legitimate reuse (the same control in two figures, declared), a duplicated panel by mistake, or something that needs explanation. Every result needs review by someone who knows the experiment.
The reference images
The package ships twelve synthetic images with known relations: an exact copy, the same pixels saved as TIFF, a rotation, a flip, a contrast change, a spliced lane, a 16-bit version and unrelated negatives.
library(reproimage)
dir <- ri_example_dir()
list.files(dir)
#> [1] "cells_a_16bit.png" "cells_a_16bit.tif" "cells_a.png"
#> [4] "cells_b.png" "gel_a_contrast.png" "gel_a_copy.png"
#> [7] "gel_a_flip.png" "gel_a_rot90.png" "gel_a_spliced.png"
#> [10] "gel_a.png" "gel_a.tif" "gel_b.png"Analysing a folder
res <- ri_analyze(dir)
res
#> ReproImage analysis
#> 12 images, 18 related pairs (algorithm version 1, thresholds dHash 10 / pHash 10)
#>
#> cells_a.png similar cells_a_16bit.png (identity, distances 1/4)
#> cells_a.png similar cells_a_16bit.tif (identity, distances 1/4)
#> cells_a_16bit.png identical_pixels cells_a_16bit.tif
#> gel_a.png identical_pixels gel_a.tif
#> gel_a.png similar gel_a_contrast.png (identity, distances 2/0)
#> gel_a.png identical_file gel_a_copy.png
#> gel_a.png similar gel_a_flip.png (flip, distances 0/0)
#> gel_a.png similar gel_a_rot90.png (rot270, distances 0/0)
#> gel_a.tif similar gel_a_contrast.png (identity, distances 2/0)
#> gel_a.tif identical_pixels gel_a_copy.png
#> gel_a.tif similar gel_a_flip.png (flip, distances 0/0)
#> gel_a.tif similar gel_a_rot90.png (rot270, distances 0/0)
#> gel_a_contrast.png similar gel_a_copy.png (identity, distances 2/0)
#> gel_a_contrast.png similar gel_a_flip.png (flip, distances 2/0)
#> gel_a_contrast.png similar gel_a_rot90.png (rot270, distances 2/0)
#> gel_a_copy.png similar gel_a_flip.png (flip, distances 0/0)
#> gel_a_copy.png similar gel_a_rot90.png (rot270, distances 0/0)
#> gel_a_flip.png similar gel_a_rot90.png (flip_rot90, distances 0/0)
#>
#> Requires expert review: visual relations, not evidence of misconduct.
summary(res)
#> category pairs
#> 1 identical_file 1
#> 2 identical_pixels 3
#> 3 similar 14gel_a_rot90.png is reported as similar to
gel_a.png in orientation rot270: rotating it
270 degrees counter-clockwise recovers the original. The spliced gel, in
which one lane comes from another image, is not
reported: hashes describe the whole image, and partial duplication
inside an otherwise different image is out of scope for algorithm
version 1.
The pairs are a data frame, ready for further analysis:
pairs <- as.data.frame(res)
pairs[pairs$category == "similar", c("a", "b", "orientation", "dhash_distance", "phash_distance")]
#> a b orientation dhash_distance
#> 1 cells_a.png cells_a_16bit.png identity 1
#> 2 cells_a.png cells_a_16bit.tif identity 1
#> 5 gel_a.png gel_a_contrast.png identity 2
#> 7 gel_a.png gel_a_flip.png flip 0
#> 8 gel_a.png gel_a_rot90.png rot270 0
#> 9 gel_a.tif gel_a_contrast.png identity 2
#> 11 gel_a.tif gel_a_flip.png flip 0
#> 12 gel_a.tif gel_a_rot90.png rot270 0
#> 13 gel_a_contrast.png gel_a_copy.png identity 2
#> 14 gel_a_contrast.png gel_a_flip.png flip 2
#> 15 gel_a_contrast.png gel_a_rot90.png rot270 2
#> 16 gel_a_copy.png gel_a_flip.png flip 0
#> 17 gel_a_copy.png gel_a_rot90.png rot270 0
#> 18 gel_a_flip.png gel_a_rot90.png flip_rot90 0
#> phash_distance
#> 1 4
#> 2 4
#> 5 0
#> 7 0
#> 8 0
#> 9 0
#> 11 0
#> 12 0
#> 13 0
#> 14 0
#> 15 0
#> 16 0
#> 17 0
#> 18 0Thresholds
Two images are similar when both the dHash and the pHash Hamming distances (out of 64 bits) are at most 10. Lower thresholds give fewer, more certain pairs; higher thresholds catch heavier edits at the cost of false positives. The thresholds are recorded in every result.
strict <- ri_analyze(dir, thresholds = list(dhash = 2, phash = 2))
summary(strict)
#> category pairs
#> 1 identical_file 1
#> 2 identical_pixels 3
#> 3 similar 12Report and provenance
ri_write() writes the result as JSON and CSV, a
self-contained HTML report with side-by-side thumbnails, and an RO-Crate
record that lists every input with its checksum, the package and
algorithm versions and the parameters. Archived with the images, it lets
anyone repeat the check.
out <- file.path(tempdir(), "reproimage-vignette")
ri_write(res, out)
list.files(out)
#> [1] "pairs.csv" "report.html" "result.json"
#> [4] "ro-crate-metadata.json"
crate <- jsonlite::fromJSON(file.path(out, "ro-crate-metadata.json"), simplifyVector = FALSE)
vapply(crate[["@graph"]][1:4], function(e) e[["@type"]], "")
#> [1] "CreativeWork" "Dataset" "CreateAction"
#> [4] "SoftwareApplication"
unlink(out, recursive = TRUE)One specification, two implementations
The algorithms are written down in ALGORITHMS.md in the
source repository: decoding to a 0 to 255 scale (16-bit samples divided
by 257), a fixed grey conversion, a block resize that avoids library
resampling, a comparison tolerance that makes results independent of
floating-point summation order, and the hash and pair rules. This
package and the ReproImage Python tool implement it independently. Both
are tested against the expected results of the reference images, which
ship with the package:
Known limits
- Whole-image hashes miss duplicated regions inside otherwise different images (such as the spliced lane above).
- Strong crops or resizing can push related images past the thresholds.
- 16-bit colour images are analysed, but decoders reduce them differently, so they are not part of the conformance tests.