import numpy as np
from numpy import zeros
from dipy.segment.threshold import upper_bound_by_percent, upper_bound_by_rate
from numpy.testing import assert_equal, run_module_suite


def test_adjustment():

    imga = zeros([128, 128])

    for y in range(128):
        for x in range(128):
            if y > 10 and y < 115 and x > 10 and x < 115:
                imga[x, y] = 100
            if y > 39 and y < 88 and x > 39 and x < 88:
                imga[x, y] = 150
            if y > 59 and y < 69 and x > 59 and x < 69:
                imga[x, y] = 255

    # rate = 0.1
    high_1 = upper_bound_by_rate(imga)
    high_2 = upper_bound_by_percent(imga)
    vol1 = np.interp(imga, xp=[imga.min(), high_1], fp=[0, 255])
    vol2 = np.interp(imga, xp=[imga.min(), high_2], fp=[0, 255])
    count2 = (88 - 40) * (88 - 40)
    count1 = (114 - 10) * (114 - 10)
    count3 = (69 - 60) * (69 - 60)
    count1_test = 0
    count2_test = 0
    count3_test = 0

    count2_upper = (88 - 40) * (88 - 40)
    count1_upper = (114 - 10) * (114 - 10)
    count3_upper = (69 - 60) * (69 - 60)
    count1_upper_test = 0
    count2_upper_test = 0
    count3_upper_test = 0

    if high_1 < 150:
        count3 = count2

    if high_2 < 150:
        count3_upper = count2_upper

    for i in range(128):
        for j in range(128):
            if vol1[i][j] == 255:
                count3_test = count3_test + 1
            if vol1[i][j] > 220:
                count2_test = count2_test + 1
            if vol1[i][j] > 0:
                count1_test = count1_test + 1

    for i in range(128):
        for j in range(128):
            if vol2[i][j] == 255:
                count3_upper_test = count3_upper_test + 1
            if vol2[i][j] > 220:
                count2_upper_test = count2_upper_test + 1
            if vol2[i][j] > 0:
                count1_upper_test = count1_upper_test + 1

    assert_equal(count2, count2_test)
    assert_equal(count1, count1_test)
    assert_equal(count3, count3_test)

    assert_equal(count2_upper, count2_upper_test)
    assert_equal(count1_upper, count1_upper_test)
    assert_equal(count3_upper, count3_upper_test)


if __name__ == '__main__':
    run_module_suite()

@@ -844,32 +844,33 @@
 0) * (114 - 10)%0A
+#
     count3 = (69
@@ -920,32 +920,33 @@
 count2_test = 0%0A
+#
     count3_test 
@@ -1034,16 +1034,17 @@
 4 - 10)%0A
+#
     coun
@@ -1120,32 +1120,33 @@
 _upper_test = 0%0A
+#
     count3_upper
@@ -1164,106 +1164,61 @@
     
-if high_1 %3C 150:%0A        count3 = count2%0A%0A    if high_2 %3C 150:%0A        count3_upper = count2_upper
+value1 = np.unique(vol1)%0A    value2 = np.unique(vol2)
 %0A%0A  
@@ -1261,32 +1261,33 @@
  in range(128):%0A
+#
             if v
@@ -1296,32 +1296,33 @@
 1%5Bi%5D%5Bj%5D == 255:%0A
+#
                 
@@ -1371,35 +1371,41 @@
 if vol1%5Bi%5D%5Bj%5D %3E 
-220
+value1%5B1%5D
 :%0A              
@@ -1560,32 +1560,33 @@
  in range(128):%0A
+#
             if v
@@ -1603,16 +1603,17 @@
 == 255:%0A
+#
         
@@ -1694,11 +1694,17 @@
 %5D %3E 
-220
+value2%5B1%5D
 :%0A  
@@ -1845,24 +1845,25 @@
 r_test + 1%0A%0A
+%0A
     assert_e
@@ -1922,24 +1922,25 @@
 ount1_test)%0A
+#
     assert_e
@@ -2058,32 +2058,33 @@
 nt1_upper_test)%0A
+#
     assert_equal
@@ -2118,17 +2118,16 @@
 _test)%0A%0A
-%0A
 if __nam

modify the test_adjustment