Esempio n. 1
0
    def test_tif_series_2otsu_Y23(self):
        frame_list = glob("./test_resources/Y23_0.4X_raw_tifs/*.tif")
        for idx in range(400, 450):
            frame = frame_list[idx]
            self.image = np.array(Image.open(frame))
            self.thresholds = otsu(self.image, nclasses=2)
            if idx == 425:
                # Plot intensity histogram and thresholds
                plt.hist(self.image.flatten(), bins=256, log=True)
                for t in self.thresholds:
                    plt.axvline(t, color='r')
                plt.title('Y23 using class=2')
                plt.draw()
                plt.savefig('Y23_2-class.png', dpi=300)
                plt.clf()
                Image.open('Y23_2-class.png').show()

                # Plot actual data and thresholded
                edge = feature.canny(self.image > self.thresholds[0])
                highlight = np.copy(self.image)
                highlight[edge] = 2 * self.image.max() - self.image.min()
                fig = plt.figure()
                ax11 = fig.add_subplot(221)
                ax12 = fig.add_subplot(222)
                ax21 = fig.add_subplot(223)
                ax22 = fig.add_subplot(224)
                ax11.imshow(self.image)
                ax12.imshow(self.image > self.thresholds[0])
                ax21.imshow(highlight)
                ax22.imshow(edge)
                plt.show()
Esempio n. 2
0
    def test_tif_series_2otsu_Y23(self):
        frame_list = glob("./test_resources/Y23_0.4X_raw_tifs/*.tif")
        for idx in range(400,450):
            frame = frame_list[idx]
            self.image = np.array(Image.open(frame))
            self.thresholds = otsu(self.image, nclasses=2)
            if idx==425:
                # Plot intensity histogram and thresholds
                plt.hist(self.image.flatten(), bins=256, log=True)
                for t in self.thresholds:
                    plt.axvline(t, color='r')
                plt.title('Y23 using class=2')
                plt.draw()
                plt.savefig('Y23_2-class.png', dpi=300)
                plt.clf()
                Image.open('Y23_2-class.png').show()

                # Plot actual data and thresholded
                edge = feature.canny(self.image>self.thresholds[0])
                highlight = np.copy(self.image)
                highlight[edge] = 2*self.image.max() - self.image.min()
                fig = plt.figure()
                ax11 = fig.add_subplot(221)
                ax12 = fig.add_subplot(222)
                ax21 = fig.add_subplot(223)
                ax22 = fig.add_subplot(224)
                ax11.imshow(self.image)
                ax12.imshow(self.image>self.thresholds[0])
                ax21.imshow(highlight)
                ax22.imshow(edge)
                plt.show()
Esempio n. 3
0
 def test_three_class_otsu(self):
     self.thresholds = otsu(self.image, nclasses=3)
     logger.info("three-classes: {}".format(self.thresholds))
     array2image(128 * (self.image > self.thresholds[0]) + 127 *
                 (self.image > self.thresholds[1])).show()
     assert np.allclose(self.thresholds, (82.51953125, 145.01953125)), \
         'Three-class Otsu threshold [{}] != {}'.format(
             self.thresholds, (82.51953125, 145.01953125))
Esempio n. 4
0
 def test_two_class_otsu(self):
     # run test one
     self.thresholds = otsu(self.image)
     logger.info("two-class: {}".format(self.thresholds))
     array2image(255 * (self.image > self.thresholds[0])).show()
     assert np.isclose(self.thresholds[0], 115.72265625), \
         'Two-class Otsu threshold ({}) != {}'.format(
             self.thresholds[0], 115.72265625)
Esempio n. 5
0
 def test_three_class_otsu(self):
     self.thresholds = otsu(self.image, nclasses=3)
     logger.info("three-classes: {}".format(self.thresholds))
     array2image(128*(self.image > self.thresholds[0]) +
                 127*(self.image > self.thresholds[1])).show()
     assert np.allclose(self.thresholds, (82.51953125, 145.01953125)), \
         'Three-class Otsu threshold [{}] != {}'.format(
             self.thresholds, (82.51953125, 145.01953125))
Esempio n. 6
0
 def test_two_class_otsu(self):
     # run test one
     self.thresholds = otsu(self.image)
     logger.info("two-class: {}".format(self.thresholds))
     array2image(255*(self.image > self.thresholds[0])).show()
     assert np.isclose(self.thresholds[0], 115.72265625), \
         'Two-class Otsu threshold ({}) != {}'.format(
             self.thresholds[0], 115.72265625)
Esempio n. 7
0
 def test_four_class_otsu(self):
     self.thresholds = otsu(self.image, nclasses=4)
     logger.info("four-classes: {}".format(self.thresholds))
     array2image(85 * (self.image > self.thresholds[0]) + 170 *
                 (self.image > self.thresholds[1]) + 255 *
                 (self.image > self.thresholds[2])).show()
     assert np.allclose(self.thresholds, (68.84765625, 123.53515625, 168.45703125)), \
         'Four-class Otsu threshold [{}] != {}'.format(
             self.thresholds, (68.84765625, 123.53515625, 168.45703125))
Esempio n. 8
0
 def test_four_class_otsu(self):
     self.thresholds = otsu(self.image, nclasses=4)
     logger.info("four-classes: {}".format(self.thresholds))
     array2image( 85*(self.image > self.thresholds[0]) +
                 170*(self.image > self.thresholds[1]) +
                 255*(self.image > self.thresholds[2])).show()
     assert np.allclose(self.thresholds, (68.84765625, 123.53515625, 168.45703125)), \
         'Four-class Otsu threshold [{}] != {}'.format(
             self.thresholds, (68.84765625, 123.53515625, 168.45703125))
Esempio n. 9
0
 def test_tif_series_3otsu_M04(self):
     frame_list = glob("./test_resources/M04_0.4X_raw_tifs/*.tif")
     for idx in range(400, 450):
         frame = frame_list[idx]
         self.image = np.array(Image.open(frame))
         self.thresholds = otsu(self.image, nclasses=3)
         if idx == 425:
             plt.hist(self.image.flatten(), bins=256, log=True)
             for t in self.thresholds:
                 plt.axvline(t, color='r')
             plt.title('M04 using class=3')
             plt.draw()
             plt.savefig('M04_3-class.png', dpi=300)
             plt.clf()
             Image.open('M04_3-class.png').show()
Esempio n. 10
0
 def test_tif_series_3otsu_M04(self):
     frame_list = glob("./test_resources/M04_0.4X_raw_tifs/*.tif")
     for idx in range(400,450):
         frame = frame_list[idx]
         self.image = np.array(Image.open(frame))
         self.thresholds = otsu(self.image, nclasses=3)
         if idx==425:
             plt.hist(self.image.flatten(), bins=256, log=True)
             for t in self.thresholds:
                 plt.axvline(t, color='r')
             plt.title('M04 using class=3')
             plt.draw()
             plt.savefig('M04_3-class.png', dpi=300)
             plt.clf()
             Image.open('M04_3-class.png').show()