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

Per-channel contrast #153

Merged
merged 2 commits into from
Aug 29, 2018
Merged

Per-channel contrast #153

merged 2 commits into from
Aug 29, 2018

Conversation

timholy
Copy link
Member

@timholy timholy commented Aug 27, 2018

This is a tiny change on top of #145, which will hopefully get it passing tests. CC @Cody-G

@Cody-G
Copy link
Contributor

Cody-G commented Aug 27, 2018

Looks like it's still happening. In case it's helpful you can still get an error on master (#151) if you use julia 0.6.4 on our cannon server with this package directory: /home/cody/Desktop/jpacks. You'll get the error on the first run but not again unless you uninstall ImageMagick. Curiously this doesn't happen with the default julia 0.6.3 we're using on cannon (and same package directory). For some reason that one doesn't prompt to install ImageMagick when running tests. I have no idea why that might be. Instead I downloaded a 0.6.4 binary to get the error reliably on cannon.

@timholy timholy force-pushed the Cody-G-cjg/color_contrast2 branch 5 times, most recently from e6ea5ef to 4766f54 Compare August 28, 2018 09:04
@timholy timholy force-pushed the Cody-G-cjg/color_contrast2 branch from 4766f54 to b8f4d8a Compare August 29, 2018 14:06
Copy link
Member Author

@timholy timholy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of comments about the changes. I am optimistic this will pass.

src/ImageView.jl Outdated
@@ -476,11 +476,11 @@ function histsignals(enabled::Signal, defaultimg, img::Signal, clim::Signal{CLim
return histsigs
end

function scaleminmax(mtyp::DataType, cmin::AbstractRGB{T}, cmax::AbstractRGB{T}) where {T}
function scaleminmax(::Type{Tout}, cmin::AbstractRGB{T}, cmax::AbstractRGB{T}) where {T,Tout}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes this function inferrable. Since it runs on every pixel, that's important. A DataType type is typically a recipe for non-inferrability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this brings out a longstanding point of confusion for me. Kind of amazing that I still don't get this right. I thought that annotating mtyp in this case was only for readability / catching errors and did not affect inferrability. I thought that as long as the compiler can infer the type of mtyp and all operations within the scaleminmax are themselves type stable then the entire scaleminmax function should be type stable. But am I correct that data types are fundamentally non-inferrable and for this reason the Type{xxx} construct was invented to wrap a datatype and make it inferrable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, types-as-arguments are in a bit of a special category. You can think of arguments as tuples, and type-elements of tuples "lose" their type info:

julia> typeof((1,"hello",Int))
Tuple{Int64,String,DataType}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this makes sense now, thanks! And it's helpful to know that args are just Tuples in case I forget this again.

src/ImageView.jl Outdated
r = scaleminmax(T, red(cmin), red(cmax))
g = scaleminmax(T, green(cmin), green(cmax))
b = scaleminmax(T, blue(cmin), blue(cmax))
return x->mtyp(r(red(x)), g(green(x)), b(blue(x)))
return x->Tout(nanz(r(red(x))), nanz(g(green(x))), nanz(b(blue(x))))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes an error when displaying this test image.

src/ImageView.jl Outdated
@@ -504,13 +504,16 @@ function prep_contrast(img::Signal, clim::Signal{CLim{T}}) where {T}
# Return a signal corresponding to the scaled image
imgc = map(img, clim; name="clim-mapped image") do image, cl
cmin, cmax = safeminmax(cl.min, cl.max)
mtyp = T<:GrayLike ? Gray{N0f8} : T
smm = scaleminmax(mtyp, cmin, cmax)
smm = scaleminmax(outtype(T), cmin, cmax)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be strictly necessary, but it coerces images into a display format (N0f8 storage) which catches some problems earlier and uses less memory than, e.g., RGB{Float64}.

@timholy timholy merged commit 3ab9fa4 into master Aug 29, 2018
@timholy timholy deleted the Cody-G-cjg/color_contrast2 branch August 29, 2018 14:16
@timholy
Copy link
Member Author

timholy commented Aug 29, 2018

Thank you for your patience---and especially, your contribution---@Cody-G!

@Cody-G
Copy link
Contributor

Cody-G commented Aug 29, 2018

Thanks for chasing down this nasty error and getting it merged!

@ghost ghost mentioned this pull request Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants