Exemple #1
0
    def AutoGroup(self):
        from ooflib.common import color
        def colordiff(c1,c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2
        # Dictionary of nearest pure colors and sizes of the
        # corresponding groups, which will not have exactly this
        # color, but will be closer to it than to any other color (in
        # colordiff measure).
        expected_sizes = {color.magenta : 2404,
                          color.RGBColor(1.0,1.0,1.0) : 4781,
                          color.RGBColor(0.0,0.0,0.0) : 2585,
                          color.blue : 2947,
                          color.green : 4795,
                          color.cyan : 1001,
                          color.yellow : 3617,
                          color.red : 370 }

        OOF.Image.AutoGroup(image="small.ppm:small.ppm")
        ms = microstructure.getMicrostructure("small.ppm")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 8)
        for name in groups:
#             rgb = eval(name)
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb,c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])
Exemple #2
0
    def AutoGroup(self):
        from ooflib.common import color
        def colordiff(c1,c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2
        # Dictionary of nearest pure colors and sizes of the
        # corresponding groups, which will not have exactly this
        # color, but will be closer to it than to any other color (in
        # colordiff measure).
        expected_sizes = {color.magenta : 2404,
                          color.RGBColor(1.0,1.0,1.0) : 4781,
                          color.RGBColor(0.0,0.0,0.0) : 2585,
                          color.blue : 2947,
                          color.green : 4795,
                          color.cyan : 1001,
                          color.yellow : 3617,
                          color.red : 370 }

        OOF.Image.AutoGroup(image="small.ppm:small.ppm")
        ms = microstructure.getMicrostructure("small.ppm")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 8)
        for name in groups:
#             rgb = eval(name)
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb,c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])
 def redgroup(self):
     from ooflib.common import color
     def colordiff(c1,c2):
         return (c1.red-c2.red)**2 + \
                (c1.green-c2.green)**2 + \
                (c1.blue-c2.blue)**2
     diff = None
     for name in self.ms().groupNames():
         rgb = color.rgb_from_hex(name)
         red_diff =  colordiff(rgb, color.red)
         if diff==None or red_diff < diff:
             red_name = name
             diff =  red_diff
     OOF.PixelGroup.Rename(microstructure="mat_test",
                           group=red_name, new_name="red")
Exemple #4
0
 def redgroup(self):
     from ooflib.common import color
     def colordiff(c1,c2):
         return (c1.red-c2.red)**2 + \
                (c1.green-c2.green)**2 + \
                (c1.blue-c2.blue)**2
     diff = None
     for name in self.ms().groupNames():
         rgb = color.rgb_from_hex(name)
         red_diff =  colordiff(rgb, color.red)
         if diff==None or red_diff < diff:
             red_name = name
             diff =  red_diff
     OOF.PixelGroup.Rename(microstructure="mat_test",
                           group=red_name, new_name="red")
Exemple #5
0
    def Rich_MS_Copy(self):
        from ooflib.common import color
        OOF.Image.AutoGroup(image="small.ppm:small.ppm")
        OOF.Graphics_1.Toolbox.Pixel_Select.Circle(
            source="small.ppm:small.ppm",
            points=[Point(66.0, 55.0), Point(87.6, 41.8)],
            shift=0,
            ctrl=0)
        OOF.Microstructure.Copy(microstructure="small.ppm", name="copy")

        # Essentially a re-run of the autogroup test.
        def colordiff(c1, c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2

        # Dictionary of nearest pure colors and sizes of the
        # corresponding groups, which will not have exactly this
        # color, but will be closer to it than to any other color (in
        # colordiff measure).
        expected_sizes = {
            color.magenta: 2404,
            color.RGBColor(1.0, 1.0, 1.0): 4781,
            color.RGBColor(0.0, 0.0, 0.0): 2585,
            color.blue: 2947,
            color.green: 4795,
            color.cyan: 1001,
            color.yellow: 3617,
            color.red: 370
        }
        ms = microstructure.getMicrostructure("copy")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 8)
        for name in groups:
            #            rgb = eval(name)
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb, c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])
        ps = pixelselection.pixelselectionWhoClass["copy"]
        # Selection should *not* be copied.
        self.assertEqual(ps.getObject().len(), 0)
        OOF.Microstructure.Delete(microstructure="copy")
Exemple #6
0
    def Rich_MS_Copy(self):
        from ooflib.common import color
        OOF.Image.AutoGroup(image="small.ppm:small.ppm")
        OOF.Graphics_1.Toolbox.Pixel_Select.Circle(
            source="small.ppm:small.ppm",
            points=[Point(66.0,55.0), Point(87.6,41.8)],
            shift=0,ctrl=0)
        OOF.Microstructure.Copy(microstructure="small.ppm",
                                name="copy")

        # Essentially a re-run of the autogroup test.
        def colordiff(c1,c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2
        # Dictionary of nearest pure colors and sizes of the
        # corresponding groups, which will not have exactly this
        # color, but will be closer to it than to any other color (in
        # colordiff measure).
        expected_sizes = {color.magenta : 2404,
                          color.RGBColor(1.0,1.0,1.0) : 4781,
                          color.RGBColor(0.0,0.0,0.0) : 2585,
                          color.blue : 2947,
                          color.green : 4795,
                          color.cyan : 1001,
                          color.yellow : 3617,
                          color.red : 370 }
        ms = microstructure.getMicrostructure("copy")
        groups = ms.groupNames()
        self.assertEqual(len(groups), 8)
        for name in groups:
#            rgb = eval(name)
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb,c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])
        ps = pixelselection.pixelselectionWhoClass["copy"]
        # Selection should *not* be copied.
        self.assertEqual(ps.getObject().len(), 0)
        OOF.Microstructure.Delete(microstructure="copy")
Exemple #7
0
    def Rich_Load(self):
        OOF.File.Load.Data(filename=reference_file("ms_data", "rich_ms"))
        ms = microstructure.getMicrostructure("rich")
        group = ms.findGroup("test")
        self.assertEqual(len(group), 2000)

        colorgroups = ms.groupNames()
        colorgroups.remove("test")

        from ooflib.common import color

        def colordiff(c1, c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2

        # This is a reprise of the AutoGroup test in pixel_test.
        expected_sizes = {
            color.magenta: 2404,
            color.RGBColor(1.0, 1.0, 1.0): 4781,
            color.RGBColor(0.0, 0.0, 0.0): 2585,
            color.blue: 2947,
            color.green: 4795,
            color.cyan: 1001,
            color.yellow: 3617,
            color.red: 370
        }

        for name in colorgroups:
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb, c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])

        # Find the "act1" stored active area, and check the size.
        act1 = ms.getNamedActiveArea("act1")
        self.assertEqual(len(act1.activearea.members()), 19872)
    def Rich_Load(self):
        OOF.File.Load.Data(filename=reference_file("ms_data", "rich_ms"))
        ms = microstructure.getMicrostructure("rich")
        group = ms.findGroup("test")
        self.assertEqual(len(group), 2000)

        colorgroups = ms.groupNames()
        colorgroups.remove("test")

        from ooflib.common import color

        def colordiff(c1, c2):
            return (c1.red - c2.red) ** 2 + (c1.green - c2.green) ** 2 + (c1.blue - c2.blue) ** 2

        # This is a reprise of the AutoGroup test in pixel_test.
        expected_sizes = {
            color.magenta: 2404,
            color.RGBColor(1.0, 1.0, 1.0): 4781,
            color.RGBColor(0.0, 0.0, 0.0): 2585,
            color.blue: 2947,
            color.green: 4795,
            color.cyan: 1001,
            color.yellow: 3617,
            color.red: 370,
        }

        for name in colorgroups:
            rgb = color.rgb_from_hex(name)
            key = None
            diff = None
            for c in expected_sizes.keys():
                cdiff = colordiff(rgb, c)
                if (diff is None) or (cdiff < diff):
                    key = c
                    diff = cdiff
            self.assertEqual(len(ms.findGroup(name)), expected_sizes[key])

        # Find the "act1" stored active area, and check the size.
        act1 = ms.getNamedActiveArea("act1")
        self.assertEqual(len(act1.activearea.members()), 19872)
Exemple #9
0
 def find_groups(self):
     from ooflib.common import color
     def colordiff(c1,c2):
         return (c1.red-c2.red)**2 + \
                (c1.green-c2.green)**2 + \
                (c1.blue-c2.blue)**2
     # Find the magenta group, and select it.
     mdiff = None
     bdiff = None
     magenta_name = None
     blue_name = None
     for g in self.ms().groupNames():
         gcolor = color.rgb_from_hex(g)
         cdiff = colordiff(gcolor, color.magenta)
         if (mdiff is None) or (cdiff < mdiff):
             magenta_name = g
             mdiff=cdiff
         cdiff = colordiff(gcolor, color.blue)
         if (bdiff is None) or (cdiff < bdiff):
             blue_name = g
             bdiff=cdiff
     return (magenta_name, blue_name)
Exemple #10
0
    def find_groups(self):
        from ooflib.common import color

        def colordiff(c1, c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2

        mdiff = None
        bdiff = None
        red_name = None
        blue_name = None
        for g in self.getMS().groupNames():
            gcolor = color.rgb_from_hex(g)
            cdiff = colordiff(gcolor, color.red)
            if (mdiff is None) or (cdiff < mdiff):
                red_name = g
                mdiff = cdiff
            cdiff = colordiff(gcolor, color.blue)
            if (bdiff is None) or (cdiff < bdiff):
                blue_name = g
                bdiff = cdiff
        return (red_name, blue_name)
Exemple #11
0
    def find_groups(self):
        from ooflib.common import color

        def colordiff(c1, c2):
            return (c1.red-c2.red)**2 + \
                   (c1.green-c2.green)**2 + \
                   (c1.blue-c2.blue)**2

        # Find the magenta group, and select it.
        mdiff = None
        bdiff = None
        magenta_name = None
        blue_name = None
        for g in self.ms().groupNames():
            gcolor = color.rgb_from_hex(g)
            cdiff = colordiff(gcolor, color.magenta)
            if (mdiff is None) or (cdiff < mdiff):
                magenta_name = g
                mdiff = cdiff
            cdiff = colordiff(gcolor, color.blue)
            if (bdiff is None) or (cdiff < bdiff):
                blue_name = g
                bdiff = cdiff
        return (magenta_name, blue_name)