def test3(self): import sys data1 = np.array([[ 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0], [ 0, 1, 1, 1, 1, 1, 0], [ 0, 0, 0, 0, 0, 0, 0]]) bl1 = np.zeros(data1.shape,np.intc) np1 = connectedpixels.connectedpixels(data1,bl1,0.1) data2 = np.array([[ 0, 0, 0, 0, 0, 0, 0], [ 0, 2, 0, 0, 0, 2, 0], [ 0, 2, 0, 0, 0, 2, 0], [ 0, 2, 0, 0, 0, 2, 0]]) bl2 = np.zeros(data2.shape,np.intc) np2 = connectedpixels.connectedpixels(data2,bl2,0.1) r1 = connectedpixels.blobproperties(data1, bl1, np1) r2 = connectedpixels.blobproperties(data2, bl2, np2) connectedpixels.bloboverlaps(bl1,np1,r1, bl2,np2,r2, verbose=0) # check which peaks are zeroed self.assertAlmostEqual(np.sum(r1[0]),0.,6) # Results pile up all in r2[0] self.assertAlmostEqual(np.sum(r2[1]),0.,6) from ImageD11.connectedpixels import s_1, s_I, s_I2, \ s_fI, s_ffI, s_sI, s_ssI, s_sfI, \ bb_mn_f, bb_mn_s, bb_mx_f, bb_mx_s,\ mx_I, mx_I_f, mx_I_s self.assertAlmostEqual(r2[0,s_1],11, 6) self.assertAlmostEqual(r2[0,s_I],17, 6)
def test1(self): import sys data1 = np.array([[ 1, 0, 1, 0, 0, 0, 0], [ 1, 0, 1, 0, 0, 0, 0], [ 1, 0, 1, 1, 0, 0, 0], [ 1, 1, 1, 0, 0, 0, 0]]) bl1 = np.zeros(data1.shape, np.intc) np1 = connectedpixels.connectedpixels(data1,bl1,0.1) data2 = np.array([[ 0, 0, 0, 0, 2, 0, 2], [ 0, 0, 0, 0, 2, 0, 2], [ 0, 0, 0, 2, 0, 2, 0], [ 0, 0, 0, 0, 2, 0, 2]]) bl2 = np.zeros(data2.shape,np.intc) np2 = connectedpixels.connectedpixels(data2,bl2,0.1) r1 = connectedpixels.blobproperties(data1, bl1, np1, omega=-10.0) r2 = connectedpixels.blobproperties(data2, bl2, np2, omega=10.0) connectedpixels.bloboverlaps(bl1,np1,r1, bl2,np2,r2, verbose=0) # check r1 is zeroed err = np.sum(np.ravel(r1)) self.assertAlmostEqual(err,0.,6) from ImageD11.connectedpixels import s_1, s_I, s_I2, \ s_fI, s_ffI, s_sI, s_ssI, s_sfI, \ bb_mn_f, bb_mn_s, bb_mx_f, bb_mx_s,\ bb_mn_o, bb_mx_o,\ mx_I, mx_I_f, mx_I_s # check total pixels self.assertAlmostEqual(r2[0,s_1], 18.0, 6) self.assertAlmostEqual(r2[0,s_I], 26.0, 6) self.assertAlmostEqual(r2[0,bb_mn_f], 0.0, 6) self.assertAlmostEqual(r2[0,bb_mx_f], 6.0, 6) self.assertAlmostEqual(r2[0,bb_mn_s], 0.0, 6) self.assertAlmostEqual(r2[0,bb_mx_s], 3.0, 6) self.assertAlmostEqual(r2[0,bb_mn_o], -10.0, 6) self.assertAlmostEqual(r2[0,bb_mx_o], 10.0, 6)
t = 8 NI = 3 for i in range(NI): print i, aimg = np.random.random((N * M)).reshape((N, M)).astype(np.float32) * 10 # New code bnew = np.zeros(aimg.shape, BTYPE) npnew = connectedpixels.connectedpixels(aimg, bnew, t, verbose=0) mnew = connectedpixels.blobproperties(aimg, bnew, npnew, i) print "b4new", i, npnew, mnew[:, 0].astype(int) if i > 1: npknew = connectedpixels.bloboverlaps(bnew, npnew, mnew, b0[-1], n0[-1], m0[-1], verbose=0) print "Afternew", i, npnew, mnew[:, 0].astype(int) b0.append(bnew) n0.append(npnew) m0.append(mnew) # old code bold = np.zeros(aimg.shape, BTYPE) npold = ImageD11.connectedpixels.connectedpixels(aimg, bold, t, verbose=0) mold = ImageD11.connectedpixels.blobproperties(aimg, bold, npold, i) print "b4old", i, npold, mold[:, 0].astype(int) if i > 1: npkold = ImageD11.connectedpixels.bloboverlaps(bold, npold,