Hacktoberfest 2020: Added computer vision algorithm#2946
Hacktoberfest 2020: Added computer vision algorithm#2946cclauss merged 5 commits intoTheAlgorithms:masterfrom
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? |
TanayKarve
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| 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) |
There was a problem hiding this comment.
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>
* Create meanthresholding.py * Rename meanthresholding.py to meanthreshold.py * Update meanthreshold.py * Update computer_vision/meanthreshold.py Verified this part works, thanks. Co-authored-by: Christian Clauss <cclauss@me.com> * Update computer_vision/meanthreshold.py Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: Christian Clauss <cclauss@me.com>
* Create meanthresholding.py * Rename meanthresholding.py to meanthreshold.py * Update meanthreshold.py * Update computer_vision/meanthreshold.py Verified this part works, thanks. Co-authored-by: Christian Clauss <cclauss@me.com> * Update computer_vision/meanthreshold.py Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: Christian Clauss <cclauss@me.com>
* Create meanthresholding.py * Rename meanthresholding.py to meanthreshold.py * Update meanthreshold.py * Update computer_vision/meanthreshold.py Verified this part works, thanks. Co-authored-by: Christian Clauss <cclauss@me.com> * Update computer_vision/meanthreshold.py Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: Christian Clauss <cclauss@me.com>
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.