Skip to content

Commit

Permalink
Merge d1edf06 into ae7af2d
Browse files Browse the repository at this point in the history
  • Loading branch information
aquatiko committed Apr 21, 2019
2 parents ae7af2d + d1edf06 commit 34da462
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ FITSIO 0.12
FileIO
Images
RecipesBase
Interact
ImageMagick
2 changes: 1 addition & 1 deletion src/AstroImages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ __precompile__()

module AstroImages

using FITSIO, FileIO, Images
using FITSIO, FileIO, Images, Interact

export load, AstroImage

Expand Down
20 changes: 18 additions & 2 deletions src/showmime.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
_brightness_contrast(color, matrix::AbstractMatrix{T}, brightness, contrast) where {T} =
@. color(matrix / 255 * T(contrast) + T(brightness) / 255)

"""
brightness_contrast(image::AstroImage; brightness_range = 0:255, contrast_range = 1:1000)
Visualize the fits image by changing the brightness and contrast of image.
Users can also provide their own range as keyword arguments.
"""
function brightness_contrast(img::AstroImage{T,C}; brightness_range = 0:255,
contrast_range = 1:1000) where {T,C}
@manipulate for brightness in brightness_range, contrast in contrast_range
_brightness_contrast(C, img.data, brightness, contrast)
end
end

# This is used in Jupyter notebooks
Base.show(io::IO, mime::MIME"image/png", img::AstroImage; kwargs...) =
show(io, mime, render(img), kwargs...)
Base.show(io::IO, mime::MIME"text/html", img::AstroImage; kwargs...) =
show(io, mime, brightness_contrast(img), kwargs...)
19 changes: 17 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AstroImages, FITSIO, Images, Random
using AstroImages, FITSIO, Images, Random, Widgets

using Test

import AstroImages: _float, render
import AstroImages: _float, render, _brightness_contrast, brightness_contrast

@testset "Conversion to float and fixed-point" begin
@testset "Float" begin
Expand Down Expand Up @@ -44,6 +45,19 @@ end
rm(fname, force = true)
end

@testset "Control contrast" begin
@test @inferred(_brightness_contrast(Gray, ones(Float32, 2, 2), 100, 100)) isa
Array{Gray{Float32},2}
Random.seed!(1)
M = rand(2, 2)
@test @inferred(_brightness_contrast(Gray, M, 100, 100))
Gray.([0.48471895908315565 0.514787046406301;
0.5280458879184159 0.39525854250610226]) rtol = 1e-12
@test @inferred(_brightness_contrast(Gray, M, 0, 255)) == Gray.(M)
@test @inferred(_brightness_contrast(Gray, M, 255, 0)) == Gray.(ones(size(M)))
@test @inferred(_brightness_contrast(Gray, M, 0, 0)) == Gray.(zeros(size(M)))
@test brightness_contrast(AstroImage(M)) isa Widgets.Widget{:manipulate,Any}
end

@testset "default handler" begin
fname = tempname() * ".fits"
Expand Down Expand Up @@ -107,4 +121,5 @@ end
end
rm(fname, force = true)
end

include("plots.jl")

0 comments on commit 34da462

Please sign in to comment.