-
Notifications
You must be signed in to change notification settings - Fork 17
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
Display ROI #40
base: master
Are you sure you want to change the base?
Display ROI #40
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more convenient to make scale
, align
and color
optional. With the thickness feature implemented #31, we could also expose a border_width
keyword.
scale
: we can inferscale
so thatmaximum(size(img) ./ size(resize(img_roi, scale)) == 2
, orprod(size(img)) / prod(size(resize(img_roi, scale))) == 6
(or8
)align
: we can infer thealign
to be the first option that doesn't introduce overlap.color
: it depends on personal preferences, but I guess most people won't be sensitive to whatever color we make as a default value.
Hence also does not use Point to denote the diagonal points of the rectangle so as to avoid confusion. Let me know if I assumed wrong.
I was always confused that Point(x, y)
represents (second_dim, first_dim)
😕 We can file an issue for further discussion on whether we should change this.
IMO, It is less confusing to make roi::Union{NTuple{2, <:AbstractUnitRange}, CartesianIndices{2}}
, how do you think?
src/roi.jl
Outdated
function inset_roi( | ||
img::AbstractArray{T, 2}, | ||
roi::NTuple{2, NTuple{2, <:Int}}, | ||
scale::R, | ||
align::AlignOptions, | ||
color::C | ||
) where {T<:Colorant, R<:Real, C<:Colorant} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If roi
is the top-left corner of the image, and we set align = top_left
, there can be some overlap here.
This won't be a big issue as people are using it in a try-and-see manner.
It would be more convenient to make align
optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this
src/roi.jl
Outdated
function inset_roi( | ||
img::AbstractArray{T, 2}, | ||
roi::NTuple{2, NTuple{2, <:Int}}, | ||
scale::R, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to ensure scale
is positive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Some considerations:
|
These arguments are now optional. Is #31 ready to merge, or should I wait before rebasing?
I guess that is to keep
Yes, done! |
What happened to the tests? Error while compiling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appropriate usage of CartesianIndex
helps make codes simpler than you'd imagine, so I recommend you to take a look at this blog. And perhaps another example that I just wrote down yesterday: JuliaImages/ImageFiltering.jl#179
I've suggested some changes to your code so that you can use it as a start.
These arguments are now optional. Is #31 ready to merge, or should I wait before rebasing?
We don't need to wait for #31 given that it's inactive for a long time. Also, I don't think that code is nicely coded in Julia -- the API style. I've opened an issue #42 so that we can discuss this there.
if typeof(roi) <: CartesianIndices{2} | ||
sx = first(roi)[1] | ||
sy = first(roi)[2] | ||
|
||
ex = last(roi)[1] | ||
ey = last(roi)[2] | ||
else | ||
sx = first(first(roi)) | ||
ex = last(first(roi)) | ||
|
||
sy = first(last(roi)) | ||
ey = last(last(roi)) | ||
|
||
end | ||
|
||
if sx >= ex || sy >= ey | ||
throw(ArgumentError("Region of interest must be an increasing range")) | ||
end | ||
|
||
if !checkindex(Bool, axes(img, 1), sx) || | ||
!checkindex(Bool, axes(img, 1), ex) || | ||
!checkindex(Bool, axes(img, 2), sy) || | ||
!checkindex(Bool, axes(img, 2), ey) | ||
throw(ArgumentError("Region of interest lies out of image")) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CartesianIndex
helps handle N-D case in a generic way:
R = CartesianIndices(img)
roi = CartesianIndices(roi)
I_first, I_last = first(roi), last(roi)
(I_first in R && I_last in R) || throw(ArgumentError("Region of interest lies out of image"))
We don't need to check sx >= ex || sy >= ey
because cases like -2:-1:-5
is not a AbstractUnitRange
Ref: JuliaGraphics/ColorTypes.jl#209 You can temporarily disable the nightly test to continue this:
|
Maybe fixed in ColorTypes v0.10.7. |
Yeah,I had quite a lot of trouble with this too 😓 🤣 for rectangle one.I read this part just now,so we maybe need some changes in #52 and ofcourse on how the data is handled.CartesianIndex + Point,it gets eerily hard to makes sense of it.. |
Adds the
display_roi
functionality.Adds
inset_roi
that enlarges and displays a single ROI inside the image itself.Some considerations:
x
(first coordinate) refers to columns andy
(second coordinate) refers to rows convention, because ROIs are more likely to be interpreted in terms of pixel indices, I assumed. Hence also does not usePoint
to denote the diagonal points of the rectangle so as to avoid confusion. Let me know if I assumed wrong.draw
does not, because highlighting ROIs in color on gray images is fairly common.The second commit e71f317 adds a function signature that could support showing up to 4 different ROIs inside the image along the 4 corners, let me know if something like that would be desirable.
Example
@johnnychen94