-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
temp commit from sc5, work on SDI and add cutoutview
- Loading branch information
scexao6
committed
Mar 13, 2024
1 parent
addf1f8
commit a7d6fda
Showing
5 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
name = "HCIToolbox" | ||
uuid = "b6cd55e5-4d02-4e12-b82c-005f67e784bf" | ||
authors = ["Miles Lucas <[email protected]>"] | ||
version = "0.6.3" | ||
version = "0.6.4" | ||
|
||
[deps] | ||
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298" | ||
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" | ||
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" | ||
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
LossFunctions = "30fc2ffe-d236-52d8-8643-a9d8f7c094a7" | ||
Optim = "429524aa-4258-5aef-a3af-852621145aeb" | ||
PaddedViews = "5432bcbf-9aad-5242-b902-cca2824c8663" | ||
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc" | ||
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" | ||
|
@@ -21,6 +23,8 @@ CoordinateTransformations = "0.5, 0.6" | |
FillArrays = "0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13" | ||
ImageTransformations = "0.9" | ||
Interpolations = "0.12, 0.13" | ||
LossFunctions = "0.11" | ||
Optim = "1" | ||
PaddedViews = "0.5" | ||
Rotations = "1" | ||
SpecialFunctions = "0.10, 1, 2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,6 @@ include("angles.jl") | |
include("scaling.jl") | ||
include("profiles.jl") | ||
|
||
include("cutout.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
struct CutoutView{T,N,M<:AbstractArray{T,N},CT,IT} <: AbstractArray{T,N} | ||
parent::M | ||
center::CT | ||
indices::IT | ||
fill::T | ||
end | ||
|
||
|
||
function CutoutView(parent::AbstractArray{T}, center, _size; fill=zero(T)) where T | ||
|
||
xlims = extrema(axes(parent, 1)) | ||
ylims = extrema(axes(parent, 2)) | ||
|
||
half_length = ones(Int, 2) .* _size ./ 2 | ||
minx = max(xlims[begin], round(Int, center[begin] - half_length[begin])) | ||
miny = max(ylims[begin], round(Int, center[end] - half_length[end])) | ||
maxx = minx + round(Int, half_length[begin] * 2) - 1 | ||
maxy = miny + round(Int, half_length[end] * 2) - 1 | ||
inds = (minx:maxx, miny:maxy,) | ||
|
||
return CutoutView(parent, center, inds, T(fill)) | ||
end | ||
|
||
function CutoutView(parent::AbstractArray{T}, _size; fill=zero(T)) where T | ||
center = HCIToolbox.center(parent) | ||
xlims = extrema(axes(parent, 1)) | ||
ylims = extrema(axes(parent, 2)) | ||
|
||
half_length = ones(Int, 2) .* _size ./ 2 | ||
minx = max(xlims[begin], round(Int, center[begin] - half_length[begin])) | ||
miny = max(ylims[begin], round(Int, center[end] - half_length[end])) | ||
maxx = minx + round(Int, half_length[begin] * 2) | ||
maxy = miny + round(Int, half_length[end] * 2) | ||
inds = (minx:maxx, miny:maxy,) | ||
|
||
return CutoutView(parent, center, inds, T(fill)) | ||
end | ||
|
||
Base.parent(view::CutoutView) = view.parent | ||
Base.size(view::CutoutView) = map(length, view.indices) | ||
Base.copy(view::CutoutView) = CutoutView(copy(parent(view)), view.center, view.indices, view.fill) | ||
Base.axes(view::CutoutView) = view.indices | ||
|
||
|
||
@propagate_inbounds function Base.getindex(view::CutoutView{T,N}, idx::Vararg{<:Integer,N}) where {T,N} | ||
@boundscheck checkbounds(parent(view), idx...) | ||
|
||
value = convert(T, parent(view)[idx...]) | ||
return value | ||
# ifelse(inside_annulus(view, idx...), , view.fill) | ||
end | ||
|
||
# @propagate_inbounds function Base.setindex!(view::CutoutView{T,N}, val, idx::Vararg{<:Integer,N}) where {T,N} | ||
# @boundscheck checkbounds(parent(view), idx...) | ||
# if inside_annulus(view, idx...) | ||
# parent(view)[idx...] = val | ||
# else | ||
# view.fill | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters