diff --git a/Homework2/Problem2_3/200_redCell.png b/Homework2/Problem2_3/200_redCell.png new file mode 100644 index 0000000..5f2028d Binary files /dev/null and b/Homework2/Problem2_3/200_redCell.png differ diff --git a/Homework2/Problem2_3/BRIEF descriptor.py b/Homework2/Problem2_3/BRIEF descriptor.py new file mode 100644 index 0000000..664e384 --- /dev/null +++ b/Homework2/Problem2_3/BRIEF descriptor.py @@ -0,0 +1,54 @@ + +# coding: utf-8 + +# In[17]: + +import numpy as np +import math +from PIL import Image, ImageDraw +import random + + +givenImg = Image.open('C:\Users\Char\Downloads\\200_redCell.png', 'r').convert('LA') +#givenImg.show() +(width, height) = givenImg.size +imgData = list(givenImg.getdata()) + +numOfPairs = 20; +samplingPairs = makeSamplingPair(numOfPairs, width, height) +print samplingPairs + +BRIEFDescriptor = makeBRIEFDescriptor(samplingPairs, numOfPairs, imgData, width, height) +print BRIEFDescriptor + + +# In[15]: + +def makeSamplingPair(numOfPairs, width, height): + samplingPairs = list(); + + for i in range(numOfPairs): + X1 = int(width*random.random()); + Y1 = int(height*random.random()); + X2 = int(width*random.random()); + Y2 = int(height*random.random()); + currSamplingPair =[[X1, Y1], [X2, Y2]] + samplingPairs.append(currSamplingPair); + + return samplingPairs; + + +# In[11]: + +def makeBRIEFDescriptor(samplingPairs, numOfPairs, imgData, width, height): + BRIEFDescriptor = list(); + for currPair in samplingPairs: + valueInPt1 = imgData[currPair[0][0]+width*currPair[0][1]][0]; + valueInPt2 = imgData[currPair[1][0]+width*currPair[1][1]][0]; + if(valueInPt1 > valueInPt2): + BRIEFDescriptor.append(1); + else: + BRIEFDescriptor.append(0); + + return BRIEFDescriptor; + diff --git a/Homework2/Problem2_3/FAST edge detector.py b/Homework2/Problem2_3/FAST edge detector.py new file mode 100644 index 0000000..0325e85 --- /dev/null +++ b/Homework2/Problem2_3/FAST edge detector.py @@ -0,0 +1,100 @@ + +# coding: utf-8 + +# In[9]: + +import numpy as np +from PIL import Image, ImageDraw + + +givenImg = Image.open('C:\Users\Char\Downloads\\200_redCell.png', 'r').convert('LA') +givenImg.show() + + + + +(width, height) = givenImg.size +pixels = list(givenImg.getdata()) +threshold = 10 +cornerList = FAST9CornerDetector(pixels, width, height, threshold) + +draw = ImageDraw.Draw(givenImg) + +for currCorner in cornerList: + draw.ellipse((currCorner[0]-1, currCorner[1]-1, currCorner[0]+1, currCorner[1]+1), + fill=0) + +givenImg.show() + + +# In[2]: + +def FAST9CornerDetector(pixelList, width, height, threshold): + cornerCoordList = list(); + for currX in range(width): + for currY in range(height): + isCorner = judgeCornerPoint(currX, currY, pixelList, width, height, threshold); + if(isCorner == True): + cornerCoordList.append([currX, currY]); + + return cornerCoordList; + + + +# In[3]: + +def judgeCornerPoint(currX, currY, pixelList, width, height, threshold): + SurrondingPoints = [[currX, currY+3], [currX+1, currY+3], [currX+2, currY+2], + [currX+3, currY+1], [currX+3, currY], [currX+3, currY-1], [currX+2, currY-2], + [currX+1, currY-3], [currX, currY-3], [currX-1, currY-3], [currX-2, currY-2], + [currX-3, currY-1], [currX-3, currY], [currX-3, currY+1], [currX-2, currY+2], + [currX-1, currY+3]] + + brightOfCurrCoord = pixelList[currX+currY*width][0]; + continuousState = 0; + + for surrCoord in SurrondingPoints: + if ((surrCoord[0] >= 0) & (surrCoord[1] >= 0) & (surrCoord[0] < width) & (surrCoord[1] < height)): + brightOfSurrCoord = pixelList[surrCoord[0]+surrCoord[1]*width][0]; + if(continuousState >= 0): + if(brightOfSurrCoord > brightOfCurrCoord+threshold): + continuousState = continuousState+1; + elif(brightOfSurrCoord < brightOfCurrCoord-threshold): + continuousState = -1; + else: + continuousState = 0; + else: + if(brightOfSurrCoord > brightOfCurrCoord+threshold): + continuousState=1; + elif(brightOfSurrCoord < brightOfCurrCoord-threshold): + continuousState = continuousState-1; + else: + continuousState = 0; + + if((continuousState == 9)|(continuousState == -9)): + return True; + + if(continuousState > 0): + for i in range(9-continuousState): + surrCoord = SurrondingPoints[i] + if ((surrCoord[0] >= 0) & (surrCoord[1] >= 0) & (surrCoord[0] < width) & (surrCoord[1] < height)): + brightOfSurrCoord = pixelList[surrCoord[0]+surrCoord[1]*width][0]; + if(brightOfSurrCoord > brightOfCurrCoord+threshold): + continuousState = continuousState+1; + + if(continuousState == 9): + return True; + + if(continuousState < 0): + for i in range(9+continuousState): + surrCoord = SurrondingPoints[i] + if ((surrCoord[0] >= 0) & (surrCoord[1] >= 0) & (surrCoord[0] < width) & (surrCoord[1] < height)): + brightOfSurrCoord = pixelList[surrCoord[0]+surrCoord[1]*width][0]; + if(brightOfSurrCoord > brightOfCurrCoord+threshold): + continuousState = continuousState-1; + + if(continuousState == -9): + return True; + + return False; +