Skip to content
Snippets Groups Projects
Commit 2ce68cd4 authored by Angeline Aguinaldo's avatar Angeline Aguinaldo
Browse files

Pixel Replication Demo fully running

parent 4977441d
Branches
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.5.1 (C:\Users\angeline\Anaconda3\python.exe)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.1 (C:\Users\angeline\Anaconda3\python.exe)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Python.iml" filepath="$PROJECT_DIR$/.idea/Python.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -32,13 +32,13 @@ def GetRandomEllipseImage(K):
import numpy as np
IMSIZE = 1000
mu1 = [500, 500]
bw = np.zeros([IMSIZE, IMSIZE], dtype=bool)
bw = np.zeros([IMSIZE, IMSIZE])
ptsCombined = np.empty([1,2])
pts = []
ptsEdge = []
bValidEllipse = False
while ~bValidEllipse:
while bValidEllipse == False:
for k in np.arange(0, K, 1, dtype=int):
pts_tmp, ptsEdge_tmp = GetRandomEllipsePts(mu1, IMSIZE)
ptsCombined = np.append(ptsCombined, pts_tmp, axis=0)
......@@ -66,8 +66,16 @@ def GetRandomEllipseImage(K):
ptsCombined = np.concatenate(pts[0:K])
bw[np.array([ptsCombined[0:,0]]), np.array([ptsCombined[0:,1]])] = 1
return bw
ellipseBounds = np.where(bw == 1)
minx = np.min(ellipseBounds[1]) - 10
maxx = np.max(ellipseBounds[1]) + 10
miny = np.min(ellipseBounds[0]) - 10
maxy = np.max(ellipseBounds[0]) + 10
bw = bw[miny:maxy, minx:maxx]
bw = np.uint8(bw)
return bw
def genEllipse(mu, cv, c, bFill):
import numpy as np
......@@ -103,7 +111,6 @@ def genEllipse(mu, cv, c, bFill):
idx = np.where(bw==1)
pts = np.transpose(np.vstack((idx[0], idx[1])))
pts = np.array(pts)
return pts, bw
......@@ -112,8 +119,6 @@ def GetRandomEllipsePts(mu, IMSIZE):
import numpy as np
from numpy.matlib import repmat
import scipy.ndimage.morphology as bwmorph
pts = []
ptsEdge = []
RADII_0 = 10
RADII_1 = 20
......@@ -128,6 +133,9 @@ def GetRandomEllipsePts(mu, IMSIZE):
pts = genEllipse(mu, cv, 1, 1)
ptsEdge = genEllipse(mu, cv, 1, 0)
pts = pts[0]
ptsEdge = ptsEdge[0]
theta = 2 * np.pi * np.random.rand()
pts = pts - np.matlib.repmat(mu, pts.shape[0], 1)
......@@ -176,3 +184,5 @@ def GetOverlap(idxPts):
break
return bNoFullOverlap
bwim = GetRandomEllipseImage(2)
\ No newline at end of file
......@@ -36,16 +36,21 @@
# and label is used to select the component to replicate
def PixelReplicate(bwim):
from numpy.matlib import repmat
import numpy as np
import cv2
print("Computing distance transform...")
bwd = cv2.distanceTransform(bwim, distanceType=cv2.DIST_L2, maskSize=5)
bwd = cv2.distanceTransform(bwim, distanceType=cv2.DIST_L2, maskSize=3)
bwd = np.asmatrix(bwd, dtype=float)
roundBwd = np.round(bwd)
nPtsRep = np.sum(roundBwd, dtype=int)
# for debugging --
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(bwd)
# ----------------
ptsRep = np.zeros((nPtsRep.astype(int), 2))
r, c = np.where(bwim == 1)
pts = np.asarray([r, c], dtype=int)
......@@ -91,6 +96,7 @@ def drawClusters(gmmfit, bwim):
clusters = gmmfit.predict(pts)
print("Clusters Found: ", np.unique(clusters)+1)
plt.figure()
plt.imshow(bwim, cmap='gray')
plt.hold(True)
print("Plotting...")
......@@ -98,7 +104,6 @@ def drawClusters(gmmfit, bwim):
for h in np.unique(clusters):
clustIdx = np.where(clusters == h)
clustIdx = clustIdx[0]
print("Cluster ", h + 1, "Indices: ", clustIdx)
plt.scatter(x=pts[clustIdx, 1], y=pts[clustIdx, 0], c=colors[h])
plt.show()
plt.hold(False)
......
......@@ -27,14 +27,13 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import cv2
import PixelRepLib as PR
import GenerateEllipseLib as GenEllipse
import PIXEL_REPLICATION_LIB as PR
import GENERATE_ELLIPSE_LIB as GenEllipse
# Generate random ellipse image
print("Generating Ellipse...")
K = 5 # number of ellipse to fit
# bwim = GenEllipse.GetRandomEllipseImage(K)
K = 2 # number of ellipse to fit
bwim = GenEllipse.GetRandomEllipseImage(K)
# You may import an image for demo by uncommenting the following code:
# im = cv2.imread('filename',cv2.CV_8UC1)
......@@ -42,9 +41,6 @@ K = 5 # number of ellipse to fit
# plt.imshow(im)
# plt.show()
im = cv2.imread('U:\Angeline\PixelRep\Ellipse.tif',cv2.CV_8UC1)
th, bwim = cv2.threshold(im, 0, 1, cv2.THRESH_BINARY)
# IMPORTANT NOTE:
# bwim only has 1 connected component. if bwim has multiple connected
# components, process each one separately
......@@ -60,8 +56,7 @@ gmmfit = PR.fitGMM(ptsRep, K)
PR.drawClusters(gmmfit, bwim)
# Draw Gaussian isocontours for triangular elliptical approximation (see online methods).
# These are exact for circles and approximate for ellipticals.
......
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment