Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
licenseplates
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
licenseplates
Commits
e1d45d10
Commit
e1d45d10
authored
Dec 02, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed import error.
parent
21c6a08e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
22 deletions
+21
-22
src/GrayscaleImage.py
src/GrayscaleImage.py
+21
-22
No files found.
src/GrayscaleImage.py
View file @
e1d45d10
from
pylab
import
imshow
,
imread
,
show
from
scipy.misc
import
imresize
from
matplotlib.pyplot
import
hist
from
scipy.misc
import
imresize
,
imsave
...
...
@@ -8,21 +7,21 @@ class GrayscaleImage:
def
__init__
(
self
,
image_path
=
None
,
data
=
None
):
if
image_path
!=
None
:
self
.
data
=
imread
(
image_path
)
extension
=
image_path
.
split
(
'.'
,
3
)[
-
1
]
if
extension
==
"jpg"
:
self
.
data
=
self
.
data
[::
-
1
]
self
.
convert_to_grayscale
()
elif
data
!=
None
:
self
.
data
=
data
def
__iter__
(
self
):
self
.
__i_x
=
-
1
self
.
__i_y
=
0
return
self
def
next
(
self
):
self
.
__i_x
+=
1
if
self
.
__i_x
==
self
.
width
:
...
...
@@ -30,47 +29,47 @@ class GrayscaleImage:
self
.
__i_y
+=
1
if
self
.
__i_y
==
self
.
height
:
raise
StopIteration
return
self
.
__i_y
,
self
.
__i_x
,
self
[
self
.
__i_y
,
self
.
__i_x
]
def
__getitem__
(
self
,
position
):
return
self
.
data
[
position
]
def
convert_to_grayscale
(
self
):
if
len
(
self
.
data
.
shape
)
>
2
:
self
.
data
=
self
.
data
[:,:,:
3
].
sum
(
axis
=
2
)
/
3
def
crop
(
self
,
rectangle
):
self
.
data
=
self
.
data
[
rectangle
.
y
:
rectangle
.
y
+
rectangle
.
height
,
self
.
data
=
self
.
data
[
rectangle
.
y
:
rectangle
.
y
+
rectangle
.
height
,
rectangle
.
x
:
rectangle
.
x
+
rectangle
.
width
]
def
show
(
self
):
imshow
(
self
.
data
,
cmap
=
"gray"
)
show
()
def
make_histogram
(
self
):
return
hist
(
self
.
data
)
def
resize
(
self
,
size
):
# size is of type float
self
.
data
=
imresize
(
self
.
data
,
size
)
def
get_shape
(
self
):
return
self
.
data
.
shape
shape
=
property
(
get_shape
)
def
get_width
(
self
):
return
self
.
get_shape
()[
1
]
width
=
property
(
get_width
)
def
get_height
(
self
):
return
self
.
get_shape
()[
0
]
height
=
property
(
get_height
)
def
in_bounds
(
self
,
y
,
x
):
return
x
>=
0
and
x
<
self
.
width
and
y
>=
0
and
y
<
self
.
height
def
save
(
self
,
path
):
imsave
(
path
,
self
.
data
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment