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

Update IntegralArrays.jl #3

Closed
wants to merge 2 commits into from

Conversation

jakewilliami
Copy link
Contributor

It looks like the code for the integral array is outdated (actually, removed). Here's a possibility for this code, which I wrote for my face detection algorithm. I suspect there are things that can be made much better, but this is a start.

It looks like the code for the integral array is outdated (actually, removed).  Here's a possibility for this code, which I wrote for my face detection algorithm.  I suspect there are things that can be made much better, but this is a start.
Copy link
Member

@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.

Thanks for doing this!

I do wonder, though, if it would make sense just to just cumsum and cumsum!. Basically I think the only thing you'd have to add would be looping over dimensions. You could even let the user select which dimensions the summation occurs over, defaulting to "all".

| . . . . | . . . . .
=#

function getImageMatrix(imageFile::AbstractString)
Copy link
Member

Choose a reason for hiding this comment

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

We follow the Julia style guide and will probably transition to the Blue style guide as well, so please using naming consistent with standard Julia choices.

=#

function getImageMatrix(imageFile::AbstractString)
img = load(imageFile)
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure we need IO functionality in this library. There's nothing here specific to an integral array representation.


function toIntegralImage(imgArr::AbstractArray)

arrRows, arrCols = size(imgArr) # get size only once in case
Copy link
Member

Choose a reason for hiding this comment

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

Note this assumes 2d. While not fatal, most of the algorithms in JuliaImages support 3d images too. Julia makes it easy to use the same code for arbitrary dimensionality.


arrRows, arrCols = size(imgArr) # get size only once in case
rowSum = zeros(arrRows, arrCols)
integralImageArr = zeros(arrRows, arrCols)
Copy link
Member

Choose a reason for hiding this comment

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

This assumes grayscale but the input arguments are general.

integralImageArr = zeros(arrRows, arrCols)

# process the first column
for x in 1:(arrRows)
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
for x in 1:(arrRows)
for x in 1:arrRows

However, to support arbitrary axes (https://julialang.org/blog/2017/04/offset-arrays/) it's best to say for x in axes(imgArr, 1)

# same as above: we cannot access a 0th element in the matrix
# our scalar accumulator s will catch the 1st row, so we only
# needed to predefine the first column before this loop
if isone(y)
Copy link
Member

Choose a reason for hiding this comment

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

Here it would be easier to use for y in 2:arrCols, or for more general axes for y in Iterators.drop(axes(y, 2), 1).

@timholy
Copy link
Member

timholy commented Aug 26, 2020

Actually, see #1. That's a pretty good implementation, so it would probably be best just to modernize that and fix the remaining unaddressed review comments. If you tackle that, make sure you preserve @mronian's contributions under his name.

This is my best attempt at adapting #1.  What do you think?
@jakewilliami
Copy link
Contributor Author

jakewilliami commented Aug 31, 2020

I updated #1 to work for 1.5. What do you think? You undoubtedly know much more Julia than I, so please let me know what still needs to be changed. Including (and especially) regarding code style and convention 😄

@timholy
Copy link
Member

timholy commented Feb 24, 2021

Hi @jakewilliami, sorry for the long delay here. In general when you're updating someone else's PR, it's best to start from their branch so you can preserve the attribution of their contribution.

I merged #1 and credited you as a co-author of my changes. Thanks for helping get this over the finish line!

@timholy timholy closed this Feb 24, 2021
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.

None yet

2 participants