-
Notifications
You must be signed in to change notification settings - Fork 34
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
Plot a georeferenced image as image #182
Comments
Sure. I think ArchGDAL has image handling now too. The question is how to set/detect that a particular tiff can be shown as an image and how to handle plotting it.
I'm not fully across band coloring in geotiff, but we should probably try to accommodate the standard |
I don't know either what makes a GeoTiff an image. Sounds like 2 is the easiest? 3 seems to be overkill for starters. 1 sounds ok too. |
Ok we can use some flag like |
R raster has plotRGB(b, r=1, g=2, b=3) https://rspatial.org/terra/pkg/6-plotting.html It's cool that you can set which layer gets which color. But we don't want a plots dep, so better to add a keyword with a plot(A; rgb_bands=(r=1, g=2, b=3)) Then we just need a conditional check for the |
Here's what I use to plot. I think it can easily be fleshed out a bit and turned into a recipe. As far as I know there is no using ImageCore
using Statistics
using Plots
using Rasters
using DimensionalData
const DD = DimensionalData
function eachband(r::Raster)
bands = dims(r, Band)
return (view(r, Band(b)) for b in bands)
end
function normalize!(raster, low=0.1, high=0.9)
for band in eachband(raster)
l = quantile(skipmissing(band), low)
h = quantile(skipmissing(band), high)
band .-= l
band ./= h - l + eps(float(eltype(raster)))
band .= clamp.(band, zero(eltype(raster)), one(eltype(raster)))
end
return raster
end
function plot_raster(r::Raster; bands=[1,2,3], low=0.02, high=0.98)
img = float32.(copy(r[Band([bands...])]))
normalize!(img, low, high)
img = permutedims(img, (Band, X, Y))
img = DimensionalData.reorder(img, DD.ForwardOrdered)
x = DD.index(reorder(dims(img, X), DD.ForwardOrdered))
y = DD.index(reorder(dims(img, Y), DD.ForwardOrdered))
plottable_img = colorview(RGB, parent(img))
Plots.plot(x,y,plottable_img,
title = string(name(r)),
xlabel = label(dims(r, X)),
ylabel = label(dims(r, Y)),
)
end |
If you want to write it up that would be awesome. We just need a keyword to pass to And/or |
I'll write it up when I find the time. Is it possible to add plot recipes for Plots and Makie at the same time without depending on them? |
Plots yes, just Recipes.jl is enough. See the current plot recipes.jl file. Would be good to have Makie.jl recipes working too, but I havent had time yet. |
Yes, but this will introduce a new dependency on MakieCore, correct? |
Totally. This use case is a reason that got separated out ;) |
Is it possible to plot a georeferenced image as an image? This is a RGB image.
Running
gives
but I expect
(the image extents are only approximate)
PyPlot.imshow(a[1:2:end,1:2:end,:])
works (minus the missing coordinates of course).Here the type of
a
:The text was updated successfully, but these errors were encountered: