Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #24

Merged
merged 3 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ read FITS files.
Installation
------------

`AstroImage.jl` is available for Julia 0.7 and later versions, and can be
`AstroImage.jl` is available for Julia 1.0 and later versions, and can be
installed with [Julia built-in package
manager](https://docs.julialang.org/en/v1/stdlib/Pkg/). This packages is not
yet registered, after entering into the package manager by pressing `]` run the
command
manager](https://docs.julialang.org/en/v1/stdlib/Pkg/).

```julia
pkg> add https://github.com/JuliaAstro/AstroImages.jl
pkg> add AstroImages
```

Usage
Expand Down Expand Up @@ -65,15 +63,33 @@ the same syntax as `load`. This command:

```julia
julia> img = AstroImage("file.fits")
AstroImages.AstroImage{UInt16,ColorTypes.Gray}[...]
AstroImages.AstroImage{UInt16,ColorTypes.Gray,1,Float64}[...]
```

will read the first extension from the `file.fits` file and wrap its content in
a `Matrix{Gray}`, that can be easily used with `Images.jl` and related packages.
will read the first valid extension from the `file.fits` file and wrap its content in
a `NTuple{N, Matrix{Gray}}`, that can be easily used with `Images.jl` and related packages.

If you are working in a Jupyter notebook, an `AstroImage` object is
automatically rendered as a PNG image.

`AstroImage` automatically extracts and store `wcs` information of images in a `NTuple{N, WCSTransform}`.

## Forming RGB image
`AstroImage` can automatically construct a RGB image if 3 different colour band data is given.

```julia
julia> img = AstroImage(RGB, ("file1.fits","file2.fits", "file3.fits"))
```
Where 1st index of `file1.fits`, `file2.fits`, `file3.fits` contains band data of red, blue and green channels respectively.

Optionally, `ccd2rgb` method can be used to form a coloured image from 3 bands without creating an `AstroImage`.

The formed image can be accessed using `img.property.rgb_image`.
`set_brightness!` and `set_contrast!` methods can be used to change brightness and contrast of formed `rgb_image`.
`add_label!` method can be used to add/store Astronomical labels in an `AstroImage`.
`reset!` method resets `brightness`, `contrast` and `label` fields to defaults and construct a fresh `rgb_image` without any brightness, contrast operations.


## Plotting an AstroImage

An `AstroImage` object can be plotted with `Plots.jl` package. Just use
Expand Down
26 changes: 26 additions & 0 deletions src/AstroImages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ function render(img::AstroImage{T,C,N}, header_number = 1) where {T,C,N}
return colorview(C, f.(_float.(img.data[header_number])))
end

"""
set_brightness!(img::AstroImage, value::AbstractFloat)

Sets brightness of `rgb_image` to value.
"""
function set_brightness!(img::AstroImage, value::AbstractFloat)
if isdefined(img.property, :rgb_image)
diff = value - img.property.brightness
Expand All @@ -183,6 +188,12 @@ function set_brightness!(img::AstroImage, value::AbstractFloat)
throw(DomainError(value, "Can't apply operation. AstroImage dosen't contain :rgb_image"))
end
end

"""
set_contrast!(img::AstroImage, value::AbstractFloat)

Sets contrast of rgb_image to value.
"""
function set_contrast!(img::AstroImage, value::AbstractFloat)
if isdefined(img.property, :rgb_image)
diff = (value / img.property.contrast)
Expand All @@ -193,9 +204,24 @@ function set_contrast!(img::AstroImage, value::AbstractFloat)
throw(DomainError(value, "Can't apply operation. AstroImage dosen't contain :rgb_image"))
end
end

"""
add_label!(img::AstroImage, x::Real, y::Real, label::String)

Stores label to coordinates (x,y) in AstroImage's property label.
"""
function add_label!(img::AstroImage, x::Real, y::Real, label::String)
push!(img.property.label, ((x,y), label))
end

"""
reset!(img::AstroImage)

Resets AstroImage property fields.

Sets brightness to 0.0, contrast to 1.0, empties label
and form a fresh rgb_image without any brightness, contrast operations on it.
"""
function reset!(img::AstroImage{T,C,N}) where {T,C,N}
img.property.contrast = 1.0
img.property.brightness = 0.0
Expand Down