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 test_2_shapes(self): for t in [np.uint8, np.int8, np.uint16, np.int16, np.int32, np.uint32, np.float32, np.float]: data = np.array( [[ 1, 0, 1, 0, 2, 0, 2], [ 1, 0, 1, 0, 2, 0, 2], [ 1, 0, 1, 0, 0, 2, 0], [ 1, 1, 1, 0, 2, 0, 2]],t) bl = np.zeros(data.shape,np.int32) connectedpixels.connectedpixels( data, bl, 0.1) # threshold err = np.sum(np.ravel(data-bl)) self.assertEqual(err, 0)
def skip_test_2_transpose(self): for t in [np.uint8, np.int8, np.uint16, np.int16, np.int32, np.uint32, np.float32, np.float]: data = np.array( [[ 1, 0, 1, 0, 2, 0, 2], [ 1, 0, 1, 0, 2, 0, 2], [ 1, 0, 1, 0, 0, 2, 0], [ 1, 1, 1, 0, 2, 0, 2]],t) bl = np.zeros(data.shape,np.int32) self.assertRaises(ValueError, connectedpixels.connectedpixels, *(np.transpose(data),bl,0.1)) connectedpixels.connectedpixels( np.transpose(data),np.transpose(bl),0.1) err = np.sum(np.ravel(data-bl)) self.assertEqual(err, 0)
def test_find_max(self): for t in [np.uint8, np.int8, np.uint16, np.int16, np.int32, np.uint32, np.float32, np.float]: data = np.array( [[ 1, 0, 1], [ 1, 0, 1], [ 1, 8, 1], [ 1, 1, 1]],t) bl = np.zeros(data.shape,np.int32) npx = connectedpixels.connectedpixels( data,bl,0.1) self.assertEqual(npx,1) err = np.sum(np.ravel(data-bl)) self.assertEqual(err, 7) # 8-1 res = connectedpixels.blobproperties(data, bl, npx, omega=22.) 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, mx_I_o # print res,res.shape self.assertAlmostEqual(res[0][s_1],10) self.assertAlmostEqual(res[0][mx_I],8) self.assertAlmostEqual(res[0][mx_I_f],1) self.assertAlmostEqual(res[0][mx_I_s],2) self.assertAlmostEqual(res[0][mx_I_o],22)
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)
assert np.allclose(drlnew, drlold), (drlold, drlnew, drlv2new) assert nnew == nold, (nnew, nold) print nnew, nold print "Seems that score is OK" print "Seems that score_and_refine is OK" print "Seems that score_and_assign is OK" print "Seems that refine_assigned is OK" print connectedpixels.s_1 BTYPE = np.intc a = np.arange(3 * 4).reshape(3, 4).astype(np.float32) r = np.zeros(a.shape, BTYPE) npk = connectedpixels.connectedpixels(a, r, 1.01, 1) print a print "Pks", npk print r # npk = connectedpixels.connectedpixels( a.astype(float), r, 1, 1) npk = connectedpixels.connectedpixels(a, r, 1.01, 1, 0) print "Pks", npk print r a = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1], [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
def skip_test_2_transpose(self): for t in [np.uint8, np.int8, np.uint16, np.int16, np.int32, np.uint32, np.float32, np.float]: data = np.array( [[ 1, 0, 1, 0, 2, 0, 2], [ 1, 0, 1, 0, 2, 0, 2], [ 1, 0, 1, 0, 0, 2, 0], [ 1, 1, 1, 0, 2, 0, 2]],t) bl = np.zeros(data.shape,np.int32) self.assertRaises(ValueError, connectedpixels.connectedpixels, *(np.transpose(data),bl,0.1)) npx = connectedpixels.connectedpixels( np.transpose(data),np.transpose(bl),0.1) self.assertEqual(npx,2) err = np.sum(np.ravel(data-bl)) self.assertEqual(err, 0) res = connectedpixels.blobproperties(data, bl, npx) 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 # print res,res.shape self.assertAlmostEqual(res[0][s_1],9) self.assertAlmostEqual(res[1][s_1],7) self.assertAlmostEqual(res[0][s_I],9) self.assertAlmostEqual(res[1][s_I],14) self.assertAlmostEqual(res[0][s_I2],9) self.assertAlmostEqual(res[1][s_I2],28) # [[ 1, 0, 1, 0, 2, 0, 2], --> Fast # [ 1, 0, 1, 0, 2, 0, 2], | # [ 1, 0, 1, 0, 0, 2, 0], | # [ 1, 1, 1, 0, 2, 0, 2]],t) V Slow # f*I: # f= 0, 1, 2, 3, 4, 5, 6 # [[ 0, 0, 2, 0, 8, 0, 12], --> Fast # [ 0, 0, 2, 0, 8, 0, 12], | # [ 0, 0, 2, 0, 0,10, 0 ], | # [ 0, 1, 2, 0, 8, 0, 12]],t) V Slow # =9 =70 self.assertAlmostEqual(res[0][s_fI],9) self.assertAlmostEqual(res[1][s_fI],70) # s*I: # s= # 0[[ 0, 0, 0, 0, 0, 0, 0], --> Fast # 1 [ 1, 0, 1, 0, 2, 0, 2], | # 2 [ 2, 0, 2, 0, 0, 4, 0], | # 3 [ 3, 3, 3, 0, 6, 0, 6]],t) V Slow # =15 =20 self.assertAlmostEqual(res[0][s_sI],15) self.assertAlmostEqual(res[1][s_sI],20) # Bounding box self.assertAlmostEqual(res[0][bb_mn_f],0) self.assertAlmostEqual(res[1][bb_mn_f],4) self.assertAlmostEqual(res[0][bb_mx_f],2) self.assertAlmostEqual(res[1][bb_mx_f],6) self.assertAlmostEqual(res[0][bb_mn_s],0) self.assertAlmostEqual(res[1][bb_mn_s],0) self.assertAlmostEqual(res[0][bb_mx_s],3) self.assertAlmostEqual(res[1][bb_mx_s],3) self.assertAlmostEqual(res[1][bb_mn_o],0) self.assertAlmostEqual(res[0][bb_mx_o],0)