Last active
July 2, 2020 09:40
-
-
Save mgautam98/35b8b79f2b93f195af50f111db182599 to your computer and use it in GitHub Desktop.
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
function radon(img::AbstractArray, theta=range(0,stop=pi,length=minimum(size(img)))) | |
ilength, iwidth = size(img) | |
idiag = sqrt(ilength^2 + iwidth^2) | |
length_pad = ceil(idiag-ilength) + 2 | |
width_pad = ceil(idiag-iwidth) + 2 | |
# Make enough padding so we don't loose anything on rotation | |
pad_image = zeros(Int(ilength+length_pad), Int(iwidth+width_pad)) | |
pad_image[Int(ceil(length_pad/2)):Int(ceil(length_pad/2)+ilength-1), | |
Int(ceil(width_pad/2)):Int(ceil(width_pad/2)+iwidth-1)] = img; | |
n = length(theta); | |
radon_img = zeros(size(pad_image,2), n) | |
# loop over all the angles | |
for i in 1:1 | |
# rotate the padded image | |
rotated = imrotate(pad_image, theta[i], axes(pad_image)) | |
# take the sum along 1 dim to get projection | |
radon_img[:, i] = sum(rotated, dims=1) | |
end | |
return radon_img | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment