Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHacktoberfest 2020: Added computer vision algorithm #2946
Conversation
|
@TanayKarve you can optimize it in magnitudes by using numpy vectorian oprerations instead of python for loops |
|
@sharpblade4 yes i was planning to do it, however wanted to write this code in pure python, thus avoiding any dependencies. what do you think? |
|
avoiding numpy to make this implement in pure python. |
|
@sharpblade4 sorry to disturb you, but its been a week, can you please accept this PR? |
|
@TanayKarve sorry for confusing you, I'm just another contributer - not an member of TheAlgorithms/Python. |
| mean = 0 | ||
| pixels = image.load() | ||
| for i in range(width): | ||
| for j in range(height): | ||
| pixel = pixels[j, i] | ||
| mean += pixel | ||
| mean //= width * height |
cclauss
Oct 16, 2020
Member
| mean = 0 | |
| pixels = image.load() | |
| for i in range(width): | |
| for j in range(height): | |
| pixel = pixels[j, i] | |
| mean += pixel | |
| mean //= width * height | |
| total = sum(sum(pixel for pixel in row) for row in image.load()) | |
| mean = total // (width * height) |
TanayKarve
Oct 16, 2020
Author
Contributor
Yes I tried using list builder comprehension initially. However image.load() returns a PixelAccess object which according to the documentation is not Iterable. Thus when running this code the following exception is thrown:
TypeError: 'PixelAccess' object is not iterable
Verified this part works, thanks. Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
|
Well done! Thanks. |
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.