Skip to content

Commit 9b901fe

Browse files
authored
Merge pull request #57 from JuliaImages/artifacts
Version 1.0
2 parents 3102f04 + 7474e48 commit 9b901fe

File tree

9 files changed

+170
-58
lines changed

9 files changed

+170
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
images/
22
deps/*.log
3+
Manifest.toml

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ language: julia
22
os:
33
- linux
44
- osx
5-
- windows
65
julia:
7-
- 1.0
86
- 1.3
97
- nightly
108
notifications:

Artifacts.toml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
["autumn_leaves.png"]
2+
git-tree-sha1 = "cb84c2e2544f3517847d90c13cc11ab911fdbc5c"
3+
4+
["blobs.gif"]
5+
git-tree-sha1 = "7b3fcffdeee78127e312d0abb44039b0d163ace6"
6+
7+
["cameraman.tif"]
8+
git-tree-sha1 = "810109202e79feee6011ca1a7ed8935be688e337"
9+
10+
["earth_apollo17.jpg"]
11+
git-tree-sha1 = "c065555adfcb3cf9c20bcd22e25d5bf88de320df"
12+
13+
["fabio_color_256.png"]
14+
git-tree-sha1 = "4aada3dffc1369c9dcdeff243ea465db215a554f"
15+
16+
["fabio_color_512.png"]
17+
git-tree-sha1 = "88cc93db49599ec8f3e25efa87e26cbb08527f7d"
18+
19+
["fabio_gray_256.png"]
20+
git-tree-sha1 = "a865772ddbdb69737e6c65775bfa385f2a3ae550"
21+
22+
["fabio_gray_512.png"]
23+
git-tree-sha1 = "087a6f6a021bf83072e023b6de5f89784ef3d064"
24+
25+
["hela-cells.tif"]
26+
git-tree-sha1 = "aa9fd486b2deeba5bdb81f69c0f462f2dde1dd20"
27+
28+
["house.tif"]
29+
git-tree-sha1 = "fc2cafa10f1aa685df851b9f19b8c7b06ee39a6d"
30+
31+
["jetplane.tif"]
32+
git-tree-sha1 = "db3f58645968c94ad801944efa760024cb5739dd"
33+
34+
["lake_color.tif"]
35+
git-tree-sha1 = "20b127f4bcf12c53873c035c03e572f3bcc2717f"
36+
37+
["lake_gray.tif"]
38+
git-tree-sha1 = "8b8ca50da02edb312129fb88fcf291f9507cdc4e"
39+
40+
["lena_color_256.tif"]
41+
git-tree-sha1 = "1cd86ce19b321e5ac8264779bec2dd9d34b707ce"
42+
43+
["lena_color_512.tif"]
44+
git-tree-sha1 = "90756db35493c3cef4887afb94bb0bb5723be8bd"
45+
46+
["lena_gray_16bit.png"]
47+
git-tree-sha1 = "395cd7fe40505d9a079baf7b60f40c79c6bddc31"
48+
49+
["lena_gray_256.tif"]
50+
git-tree-sha1 = "17c4d34059095b17f3f20ee71d2a48771b807e58"
51+
52+
["lena_gray_512.tif"]
53+
git-tree-sha1 = "48911ab84c3d0f5a7a7bb215d0181fefbb109980"
54+
55+
["lighthouse.png"]
56+
git-tree-sha1 = "8455066b3de6966cbf02f5ce3cbf5ecfbcf4765b"
57+
58+
["livingroom.tif"]
59+
git-tree-sha1 = "a3bff98dfed27ec51751345f9d0a7dabab7fa0a3"
60+
61+
["m51.tif"]
62+
git-tree-sha1 = "8b0386f5f87400db92113ebac58694d17ba25f7b"
63+
64+
["mandril_color.tif"]
65+
git-tree-sha1 = "70ca089e5f05676a3e2046f63a2931ef164afc6f"
66+
67+
["mandril_gray.tif"]
68+
git-tree-sha1 = "a42b60b1d88787d71af959409d558f4f03b4a46c"
69+
70+
["mandrill.tiff"]
71+
git-tree-sha1 = "9504f96bdf12c0bbfd1f90dff2f9210f0c72e335"
72+
73+
["moonsurface.tiff"]
74+
git-tree-sha1 = "a34653dfa27d994967ec4d9a17fd1618116bd900"
75+
76+
["mountainstream.png"]
77+
git-tree-sha1 = "05b8764b06dc0607a6468550d144310a3800b5bc"
78+
79+
["mri-stack.tif"]
80+
git-tree-sha1 = "ead8f7a5d70393124e8cdabada12140ac7b29499"
81+
82+
["multi-channel-time-series.ome.tif"]
83+
git-tree-sha1 = "a486b6128b554afeff943b4a09e4a79631554b0f"
84+
85+
["peppers_color.tif"]
86+
git-tree-sha1 = "aac2bcc734bf4ede606117cb7b33c7ee12f206d4"
87+
88+
["peppers_gray.tif"]
89+
git-tree-sha1 = "323350f5c0811cb1cfb31770854b1df637088a37"
90+
91+
["pirate.tif"]
92+
git-tree-sha1 = "0cd12429a74b8fcaf8eb04e94b445242f1f1c4b1"
93+
94+
["toucan.png"]
95+
git-tree-sha1 = "923982b64daaba909da6dfc379ee2afe5e49e067"
96+
97+
["walkbridge.tif"]
98+
git-tree-sha1 = "ac2dd42087a89cc33ae2cf078e5d84868287fbf0"
99+
100+
["woman_blonde.tif"]
101+
git-tree-sha1 = "424a4bd71bf41ae2ed87d9dbeeb081a44623fe9e"
102+
103+
["woman_darkhair.tif"]
104+
git-tree-sha1 = "43727086a784f02b67ce545a0c61b81edca41608"

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name = "TestImages"
22
uuid = "5e47fb64-e119-507b-a336-dd2b206d9990"
3-
version = "0.6"
3+
version = "1.0.0"
44

55
[deps]
66
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
77
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
8+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
89
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
910

1011
[compat]
1112
AxisArrays = "0.3"
1213
FileIO = "1"
1314
ZipFile = "0.7, 0.8"
14-
julia = "1"
15+
julia = "1.3"
1516

1617
[extras]
1718
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,19 @@ Full documentation and description of the images available in TestImages.jl can
1313

1414
## Installation
1515

16-
On Linux and OSX, this should install automatically. If you find yourself missing most of the images described in the documentation, please try `Pkg.build("TestImages")`, which should trigger another attempt to download the images.
17-
18-
In case you would like to download other images from the repository not in the standard set, you can call the ```testimage``` with the image name and it will be downloaded from the repository.
19-
20-
On Windows, the ```download``` command, used to download images from the archives, is not fully supported. You can manually download the files listed in ```deps\build.jl``` from the ```images``` folder of the ```gh-pages``` branch of this repository and place them in ```TestImages\images```.
16+
`TestImages` doesn't support image IO by itself, which means you need to install some backends on your choice, e.g., [ImageMagick.jl](https://github.com/JuliaIO/ImageMagick.jl), [QuartzImageIO](https://github.com/JuliaIO/QuartzImageIO.jl), [OMETIFF.jl](https://github.com/tlnagy/OMETIFF.jl).
2117

2218
## Usage
2319

2420
```
2521
using TestImages
2622
27-
img = testimage("cameraman")
23+
img = testimage("cameraman.tif") # fullname
24+
img = testimage("cameraman) # without extension works
25+
img = testimage("cam") # with only partial name also works
2826
```
2927

30-
The standard test images are downloaded to an `images/` directory
31-
inside this package. Any image file stored in this directory is
32-
accessible through the `testimage` function. You can supply the file
33-
extension (e.g., ".png", ".tif", etc), but it is not required. Indeed,
34-
the matching is performed using just the portion of the filename you
35-
supply, so `testimage("cam")` yields the same result.
36-
37-
In case the image is not present locally, the ```testimage``` function will check the online repository and download it for you.
28+
Images will be automatically downloaded into artifact folders (e.g., `images/` for julia `< v1.3`) when you load the image for the first time.
3829

3930
## Contributing
4031

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
environment:
22
matrix:
3-
- julia_version: 1.0
4-
- julia_version: 1
3+
- julia_version: 1.3
54
- julia_version: nightly
65

76
platform:

deps/build.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using TestImages
2+
3+
@info "Downloading standard test images"
4+
foreach(x->testimage(x; download_only=true), TestImages.remotefiles)

src/TestImages.jl

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module TestImages
22
using FileIO, AxisArrays
3+
using Pkg.Artifacts
4+
const artifacts_toml = abspath(joinpath(@__DIR__, "..", "Artifacts.toml"))
35

46
export testimage
57

6-
const imagedir = joinpath(dirname(@__FILE__), "..", "images")
7-
88
REPO_URL = "https://github.com/JuliaImages/TestImages.jl/blob/gh-pages/images/"
99

1010
remotefiles = [
@@ -46,53 +46,69 @@ remotefiles = [
4646
]
4747

4848
"""
49-
testimage(filename, [ops...])
49+
img = testimage(filename; download_only=false, [ops...])
50+
51+
Load test image that partially matches `filename`, the first match is used if there're more
52+
than one.
5053
51-
load test image that partially matches `filename`, the first match is used if there're more than one. If `ops` is specified, it will be passed to `load` function. use `TestImages.remotefiles` to get a full list of available images.
54+
If `download_only=true`, the full filepath is returned.
55+
Any other keyword arguments `ops` will be passed to image IO backend through `FileIO.load`.
5256
5357
# Example
58+
5459
```julia
5560
julia> using TestImages
56-
julia> testimage("cameraman.tif")
57-
julia> testimage("cameraman")
58-
julia> testimage("c")
61+
julia> img = testimage("cameraman.tif"); # fullname
62+
julia> img = testimage("cameraman"); # without extension works
63+
julia> img = testimage("c"); # with only partial name also works
5964
```
65+
66+
`TestImages.remotefiles` stores the full list of available images. You can also check
67+
https://testimages.juliaimages.org/
6068
"""
61-
function testimage(filename, ops...)
62-
isdir(imagedir) || mkpath(imagedir)
63-
imagefile = joinpath(imagedir, filename)
64-
if !isfile(imagefile)
65-
fls = readdir(imagedir)
66-
havefile = false
67-
for f in fls
68-
if startswith(f, filename)
69-
imagefile = joinpath(imagedir, f)
70-
havefile = true
71-
break
72-
end
73-
end
69+
function testimage(filename; download_only = false, ops...)
70+
imagefile = image_path(full_imagename(filename))
7471

75-
if !havefile
76-
@info "Could not find "*filename*" in directory images/ . Checking if it exists in the online repository."
77-
for f in remotefiles
78-
if startswith(f, filename)
79-
@info "Found "*filename*" in the online repository. Downloading to the images directory."
80-
download(REPO_URL*f*"?raw=true", joinpath(imagedir, f))
81-
havefile = true
82-
imagefile = joinpath(imagedir, f)
83-
break
84-
end
85-
end
86-
end
87-
havefile || throw(ArgumentError("$filename not found in the directory images/ or the online repository. use `TestImages.remotefiles` to get a full list of test images"))
88-
end
89-
img = load(imagefile, ops...)
90-
if startswith(basename(imagefile), "mri-stack")
72+
download_only && return imagefile
73+
74+
img = load(imagefile; ops...)
75+
if basename(imagefile) == "mri-stack.tif"
9176
# orientation is posterior-right-superior,
9277
# see http://www.grahamwideman.com/gw/brain/orientation/orientterms.htm
9378
return AxisArray(img, (:P, :R, :S), (1, 1, 5))
9479
end
9580
img
9681
end
9782

83+
"""
84+
fullname = full_imagename(shortname)
85+
86+
Get the first match of `shortname` in `TestImages.remotefiles`
87+
"""
88+
function full_imagename(filename)
89+
idx = findfirst(remotefiles) do x
90+
startswith(x, filename)
91+
end
92+
idx === nothing && throw(ArgumentError("$filename not found in the online repository, use `TestImages.remotefiles` to get a full list of test images."))
93+
94+
return remotefiles[idx]
95+
end
96+
97+
function image_path(imagename)
98+
file_hash = artifact_hash(imagename, artifacts_toml)
99+
100+
if file_hash === nothing || !artifact_exists(file_hash)
101+
new_hash = create_artifact() do artifact_dir
102+
download(REPO_URL*imagename*"?raw=true", joinpath(artifact_dir, imagename))
103+
end
104+
if file_hash === nothing
105+
bind_artifact!(artifacts_toml,
106+
imagename,
107+
new_hash)
108+
end
109+
file_hash = new_hash
110+
end
111+
return joinpath(artifact_path(file_hash), imagename)
112+
end
113+
98114
end # module

test/runtests.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ img = testimage("mri-stack")
88
@test map(step, axisvalues(img)) == (1,1,5)
99
@test_nowarn testimage("c")
1010
@test_throws ArgumentError testimage("nonexistence.png")
11-
12-
@test all([f in TestImages.remotefiles for f in readdir(TestImages.imagedir)])

0 commit comments

Comments
 (0)