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

Change variable names [UPDATED] #34

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ Initialize object
cnn = pycnn()

# object variables:
# m: width of the image (number of columns)
# n: height of image (number of rows)
# _width : width of the image (number of columns)
# _height : height of image (number of rows)
```

```python
Expand Down
27 changes: 14 additions & 13 deletions pycnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ class pycnn(object):


Attributes:
n (int): Height of the image.
m (int): Width of the image.
_height (int): Height of the image.
_width (int): Width of the image.
"""

def __init__(self):
"""Sets the initial class attributes m (width) and n (height)."""
self.m = 0 # width (number of columns)
self.n = 0 # height (number of rows)
"""Sets the initial class attributes _width (width)
and _height (height)."""
self._width = 0 # width (number of columns)
self._height = 0 # height (number of rows)

def f(self, x, t, Ib, Bu, tempA):
"""Computes the derivative of x at t.
Expand All @@ -75,9 +76,9 @@ def f(self, x, t, Ib, Bu, tempA):
tempA (:obj:`list` of :obj:`list`of :obj:`float`): Feedback
template.
"""
x = x.reshape((self.n, self.m))
x = x.reshape((self._height, self._width))
dx = -x + Ib + Bu + sig.convolve2d(self.cnn(x), tempA, 'same')
return dx.reshape(self.m * self.n)
return dx.reshape(self._height * self._width)

def cnn(self, x):
"""Piece-wise linear sigmoid function.
Expand All @@ -97,16 +98,16 @@ def validate(self, input_location):
IOError: If `input_location` does not exist or is not a file.
Exception: If file type is not supported.
"""
_, ext = os.path.splitext(input_location)
ext = ext.lstrip('.').lower()
_, file_format = os.path.splitext(input_location)
file_format = file_format.lstrip('.').lower()
if not os.path.exists(input_location):
raise IOError('File {} does not exist.'.format(input_location))
elif not os.path.isfile(input_location):
raise IOError('Path {} is not a file.'.format(input_location))
elif ext not in SUPPORTED_FILETYPES:
elif file_format not in SUPPORTED_FILETYPES:
raise Exception(
'{} file type is not supported. Supported: {}'.format(
ext, ', '.join(SUPPORTED_FILETYPES)
file_format, ', '.join(SUPPORTED_FILETYPES)
)
)

Expand All @@ -129,15 +130,15 @@ def imageprocessing(self, inputlocation, outputlocation,
representing time points.
"""
gray = img.open(inputlocation).convert('RGB')
self.m, self.n = gray.size
self._width, self._height = gray.size
u = np.array(gray)
u = u[:, :, 0]
z0 = u * initialcondition
Bu = sig.convolve2d(u, tempB, 'same')
z0 = z0.flatten()
z = self.cnn(sint.odeint(
self.f, z0, t, args=(Ib, Bu, tempA), mxstep=1000))
l = z[z.shape[0] - 1, :].reshape((self.n, self.m))
l = z[z.shape[0] - 1, :].reshape((self._height, self._width))
l = l / (255.0)
l = np.uint8(np.round(l * 255))
# The direct vectorization was causing problems on Raspberry Pi.
Expand Down