Skip to content

Commit

Permalink
Updated [v0.0.2].
Browse files Browse the repository at this point in the history
Refactored code.
Updated generaltemplate API.
  • Loading branch information
ankitaggarwal011 committed Sep 4, 2016
1 parent 15784dd commit 782d63a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ cnn = pycnn()
```

```python
# inputimagelocation: location of the input image; type: String.
# outputimagelocation: location of the output image; type: String.
# name: name of image processing method (say, Edge detection); type: string
# inputimagelocation: location of the input image; type: string.
# outputimagelocation: location of the output image; type: string.
# tempA_A: control template; type: 3 x 3 list.
# tempB_B: feedback template; type: 3 x 3 list.
# initialcondition: initial condition, type: float.
Expand All @@ -146,7 +147,7 @@ cnn = pycnn()
General image processing

```python
cnn.generaltemplates(inputimagelocation, outputimagelocation, tempA_A, tempB_B, initialcondition, Ib_b)
cnn.generaltemplates(name, inputimagelocation, outputimagelocation, tempA_A, tempB_B, initialcondition, Ib_b)
```

Edge detection
Expand Down
23 changes: 12 additions & 11 deletions pycnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,60 +78,61 @@ def imageprocessing(self, inputlocation, outputlocation, tempA, tempB, initialco
return

## general image processing for given templates
def generaltemplates(self, inputlocation = "", outputlocation = "output.png", tempA_A = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], tempB_B = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], initialcondition = 0.0, Ib_b = 0.0, t = np.linspace(0, 10.0, num=2)):
def generaltemplates(self, name = "Image processing", inputlocation = "", outputlocation = "output.png", tempA_A = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], tempB_B = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], initialcondition = 0.0, Ib_b = 0.0, t = np.linspace(0, 10.0, num=2)):
if not self.isvalid(inputlocation):
print("Invalid Location. Please try again.")
exit()
print(name, "initialized.")
self.imageprocessing(inputlocation, outputlocation, np.array(tempA_A), np.array(tempB_B), initialcondition, Ib_b, t)
print("Processing on image "+ inputlocation +" is complete and the result is saved at " + outputlocation + '.\n')
return

def edgedetection(self, inputlocation = "", outputlocation = "output.png"):
print("Edge detection initialized.")
name = "Edge detection"
tempA = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
tempB = [[-1.0, -1.0, -1.0], [-1.0, 8.0, -1.0], [-1.0, -1.0, -1.0]]
Ib = -1.0
t = np.linspace(0, 10.0, num=2)
initialcondition = 0.0
self.generaltemplates(inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
self.generaltemplates(name, inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
return

def grayscaleedgedetection(self, inputlocation = "", outputlocation = "output.png"):
print("Grayscale edge detection initialized.")
name = "Grayscale edge detection"
tempA = [[0.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 0.0]]
tempB = [[-1.0, -1.0, -1.0], [-1.0, 8.0, -1.0], [-1.0, -1.0, -1.0]]
Ib = -0.5
t = np.linspace(0, 1.0, num=100)
initialcondition = 0.0
self.generaltemplates(inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
self.generaltemplates(name, inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
return

def cornerdetection(self, inputlocation = "", outputlocation = "output.png"):
print("Corner detection initialized.")
name = "Corner detection"
tempA = [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 0.0]]
tempB = [[-1.0, -1.0, -1.0], [-1.0, 4.0, -1.0], [-1.0, -1.0, -1.0]]
Ib = -5.0
t = np.linspace(0, 10.0, num=10)
initialcondition = 0.0
self.generaltemplates(inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
self.generaltemplates(name, inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
return

def diagonallinedetection(self, inputlocation = "", outputlocation = "output.png"):
print("Diagonal line detection initialized.")
name = "Diagonal line detection"
tempA = [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 0.0]]
tempB = [[-1.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, -1.0]]
Ib = -4.0
t = np.linspace(0, 0.2, num=100)
initialcondition = 0.0
self.generaltemplates(inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
self.generaltemplates(name, inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
return

def inversion(self, inputlocation = "", outputlocation = "output.png"):
print("Inversion initialized.")
name = "Inversion"
tempA = [[0.0, 0.0, 0.0], [0.0,1.0, 0.0], [0.0, 0.0, 0.0]]
tempB = [[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [0.0, 0.0, 0.0]]
Ib = -2.0
t = np.linspace(0, 10.0, num=100)
initialcondition = 0.0
self.generaltemplates(inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
self.generaltemplates(name, inputlocation, outputlocation, tempA, tempB, initialcondition, Ib, t)
return

0 comments on commit 782d63a

Please sign in to comment.