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

Cache output of restrict to reduce redraw time #313

Closed
wants to merge 2 commits into from
Closed
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
41 changes: 32 additions & 9 deletions src/ImageView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ function imshow!(canvas::GtkObservables.Canvas{UserUnit},
imgsig::Observable,
zr::Observable{ZoomRegion{T}},
annotations::Annotations=annotations()) where T<:RInteger
pyr = ImagePyramid(imgsig)
draw(canvas, imgsig, annotations) do cnvs, image, anns
copy_with_restrict!(cnvs, image)
copy_with_restrict!(cnvs, pyr)
set_coordinates(cnvs, zr[])
draw_annotations(cnvs, anns)
end
Expand All @@ -122,8 +123,9 @@ function imshow!(frame::Union{GtkFrame,GtkAspectFrame},
imgsig::Observable,
zr::Observable{ZoomRegion{T}},
annotations::Annotations=annotations()) where T<:RInteger
pyr = ImagePyramid(imgsig)
draw(canvas, imgsig, annotations) do cnvs, image, anns
copy_with_restrict!(cnvs, image)
copy_with_restrict!(cnvs, pyr)
set_coordinates(cnvs, zr[])
set_aspect!(frame, image)
draw_annotations(cnvs, anns)
Expand All @@ -137,8 +139,9 @@ end
function imshow!(canvas::GtkObservables.Canvas,
imgsig::Observable,
annotations::Annotations=annotations())
pyr = ImagePyramid(imgsig)
draw(canvas, imgsig, annotations) do cnvs, image, anns
copy_with_restrict!(cnvs, image)
copy_with_restrict!(cnvs, pyr)
set_coordinates(cnvs, axes(image))
draw_annotations(cnvs, anns)
end
Expand All @@ -148,21 +151,41 @@ end
function imshow!(canvas::GtkObservables.Canvas,
img::AbstractMatrix,
annotations::Annotations=annotations())
pyr = ImagePyramid(img)
draw(canvas, annotations) do cnvs, anns
copy_with_restrict!(cnvs, img)
copy_with_restrict!(cnvs, pyr)
set_coordinates(cnvs, axes(img))
draw_annotations(cnvs, anns)
end
nothing
end

function copy_with_restrict!(cnvs, img::AbstractMatrix)
imgsz = size(img)
# cache of the image plus downscaled versions
ImagePyramid(img::AbstractMatrix) = Any[img]
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a function, not a type, it should be lowercase.

ImageView supports n-dimensional images, so perhaps this should be generalized beyond AbstractMatrix? Or does this only happen after slice-selection? If a user is browsing a large 3d array, would the entire pyramid be recomputed each time one changes slice planes?


function ImagePyramid(img::Observable)
pyr = Any[img[]]
on(img) do image
push!(empty!(pyr),image)
end
pyr
end

function get_image(p, i)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function get_image(p, i)
function get_restricted_image!(p, i)

Can we use more descriptive variable names than p and i?

while length(p)<i
push!(p,restrict(p[end]))
end
p[i]
end

function copy_with_restrict!(cnvs, p)
imgsz = size(p[1])
i=1
while (imgsz[1] > 2*Graphics.height(cnvs) && imgsz[2] > 2*Graphics.width(cnvs))
img = restrict(img)
imgsz = size(img)
i=i+1
imgsz = size(get_image(p,i))
end
copy!(cnvs, img)
copy!(cnvs, get_image(p, i))
end

"""
Expand Down
Loading