示例#1
0
 def test_typical(self):
     img_wrapper = image_wrap.openImageFile(
         self.locateFile('tests/images/test.png'))
     img = img_wrapper.to_array()
     img_wrapper = image_wrap.ImageWrapper(img)
     target_wrapper = image_wrap.ImageWrapper(img)
     filename = self.locateFile('tests/images/test.png')
     filename_output = tempfile.mktemp(prefix='mstcr',
                                       suffix='.png',
                                       dir='.')
     self.filesToKill.extend([filename_output])
     target_wrapper.save(filename_output)
     args, error = plugins.callPlugin('SmartMaskSelector',
                                      img_wrapper,
                                      filename,
                                      filename_output,
                                      smallw=100,
                                      smallh=100,
                                      mediumw=150,
                                      mediumh=150,
                                      largew=200,
                                      largeh=200,
                                      size=2,
                                      op=2)
     wrapper = image_wrap.openImageFile(filename_output)
     output = wrapper.to_array()
     self.assertTrue(img_wrapper.size[1] == wrapper.size[1])
     self.assertTrue(img_wrapper.size[0] == wrapper.size[0])
     self.assertTrue(len(output.shape) == 2)
     totalsize = sum(sum(output / 255))
     print totalsize
     self.assertTrue(totalsize <= (1.5 * 22500))
     self.assertTrue(totalsize >= (22500 * 0.5))
     self.assertTrue('paste_x' in args and args['paste_x'] > 0)
     self.assertTrue('paste_y' in args and args['paste_y'] > 0)
示例#2
0
 def test_something(self):
     img = numpy.random.randint(0, 255, (500, 500, 3), dtype='uint8')
     wrapper = image_wrap.ImageWrapper(img)
     filename = tempfile.mktemp(prefix='mstc', suffix='.png', dir='.')
     filename_output = tempfile.mktemp(prefix='mstcr',
                                       suffix='.png',
                                       dir='.')
     self.filesToKill.append(filename)
     wrapper.save(filename)
     self.filesToKill.append(filename_output)
     image_wrap.ImageWrapper(img).save(filename_output)
     args, error = plugins.callPlugin('MedianBlur',
                                      wrapper,
                                      filename,
                                      filename_output,
                                      kernelSize=25,
                                      percentageChange=0.5)
     wrapper = image_wrap.openImageFile(filename_output)
     output = wrapper.to_array()
     self.assertEqual(output.shape, img.shape)
     diff = abs(output - img)
     finaldiff = numpy.zeros((500, 500))
     for i in range(3):
         finaldiff = finaldiff + diff[:, :, i]
     finaldiff[finaldiff > 0] = 1
     self.assertTrue(abs(sum(sum(finaldiff)) - 62500) < 100)
示例#3
0
 def test_seam_carve(self):
     img_wrapper = image_wrap.openImageFile(self.locateFile('tests/images/test_project5.jpg'))
     img = img_wrapper.to_array()
     mask = np.zeros(img.shape).astype('uint8')
     cv2.circle(mask, (img.shape[0]/8,img.shape[1]/8), img.shape[0]/16, (255, 0, 0), -1)
     cv2.circle(mask, (img.shape[0] *5/ 8, img.shape[1] *5/ 8), img.shape[0] / 16, (0, 255, 0), -1)
     mask_wrapper = image_wrap.ImageWrapper(mask)
     mask_output = tempfile.mktemp(prefix='mstcr', suffix='.png', dir='.')
     self.addFileToRemove(mask_output)
     mask_wrapper.save(mask_output)
     target_wrapper = image_wrap.ImageWrapper(img)
     filename  = self.locateFile('tests/images/test_project5.jpg')
     filename_output = tempfile.mktemp(prefix='mstcr', suffix='.jpg', dir='.')
     self.addFileToRemove(filename_output)
     target_wrapper.save(filename_output)
     args,error = plugins.callPlugin('SeamCarve',
                         img_wrapper,
                         filename,
                         filename_output,
                         inputmaskname=os.path.abspath(mask_output),
                         percentage_height=0.95,
                         percentage_width=0.95)
     output_files = args['output_files']
     self.assertTrue('column adjuster' in output_files and os.path.exists(output_files['column adjuster']))
     self.assertTrue('row adjuster' in output_files and os.path.exists(output_files['row adjuster']))
     self.assertTrue('plugin mask' in output_files and os.path.exists(output_files['plugin mask']))
     self.assertTrue('neighbor mask' in output_files and os.path.exists(output_files['neighbor mask']))
     for v in output_files.values():
         os.remove(v)
示例#4
0
    def test_something(self):
        img = numpy.random.randint(0, 255, (500, 500, 3), dtype='uint8')
        mask = numpy.zeros((500, 500), dtype='uint8')
        mask[30:50, 30:50] = 255
        self.assertTrue(
            sum(sum(sum(img[30:50, 30:50] - img[400:420, 300:320]))) > 0)
        img_wrapper = image_wrap.ImageWrapper(img)
        target_wrapper = image_wrap.ImageWrapper(mask)
        mask_wrapper = image_wrap.ImageWrapper(mask)
        filename = tempfile.mktemp(prefix='mstc', suffix='.png', dir='.')
        filename_mask = tempfile.mktemp(prefix='mstcm', suffix='.png', dir='.')
        filename_output = tempfile.mktemp(prefix='mstcr',
                                          suffix='.png',
                                          dir='.')
        self.filesToKill.extend([filename, filename_mask, filename_output])
        img_wrapper.save(filename)
        mask_wrapper.save(filename_mask)
        target_wrapper.save(filename_output)

        args, error = plugins.callPlugin('DesignPasteClone',
                                         img_wrapper,
                                         filename,
                                         filename_output,
                                         inputmaskname=filename_mask,
                                         paste_x=300,
                                         paste_y=400)
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()
        self.assertTrue(
            sum(sum(sum(img[30:50, 30:50] - output[400:420, 300:320]))) == 0)
示例#5
0
    def test_snap(self):
        img = numpy.zeros((500, 500), dtype='uint8')
        wrapper = image_wrap.ImageWrapper(img)
        filename = tempfile.mktemp(prefix='mstc', suffix='.png', dir='.')
        filename_output = tempfile.mktemp(prefix='mstcr',
                                          suffix='.png',
                                          dir='.')
        self.filesToKill.append(filename)
        wrapper.save(filename)
        self.filesToKill.append(filename_output)
        image_wrap.ImageWrapper(img).save(filename_output)
        args, error = plugins.callPlugin('CropSelector',
                                         wrapper,
                                         filename,
                                         filename_output,
                                         percentage_width=0.1,
                                         percentage_height=0.1,
                                         eightbit_boundary='yes')
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()

        self.assertEqual(output.shape, img.shape)
        self.assertTrue('crop_x' in args and args['crop_x'] <= 56)
        self.assertTrue('crop_y' in args and args['crop_y'] <= 56)
        self.assertTrue('crop_width' in args and args['crop_width'] == 56)
        self.assertTrue('crop_height' in args and args['crop_height'] == 56)
        self.assertTrue(args['crop_y'] % 8 == 0)
        self.assertTrue(args['crop_x'] % 8 == 0)
        self.assertTrue(
            output[-(args['crop_height'] - args['crop_y'] + 1),
                   -(args['crop_width'] - args['crop_x'] + 1)] == 255)
        self.assertTrue(
            output[-(args['crop_height'] - args['crop_y'] - 1),
                   -(args['crop_width'] - args['crop_x'] - 1)] == 0)
示例#6
0
 def test_select_region_anycolor(self):
     img = numpy.zeros((500, 500, 3), dtype='uint8')
     img_wrapper = image_wrap.ImageWrapper(img)
     selector = numpy.zeros((500, 500, 3), dtype='uint8')
     selector[30:40, 30:40, :] = [200, 200, 100]
     selector[130:140, 130:140, :] = [100, 200, 100]
     selector_wrapper = image_wrap.ImageWrapper(selector)
     result, color = select_region(img_wrapper, selector_wrapper)
     result = result.to_array()
     self.assertTrue(
         numpy.all(result[30:40, 30:40, 3] != result[130:140, 130:140, 3]))
示例#7
0
 def save_adjusters(self, filename):
     """
     :param filename:
     :return: row and column uint16 PNG files
     """
     f1 = filename[:filename.find('.')] + '_adjr.png'
     f2 = filename[:filename.find('.')] + '_adjc.png'
     image_wrap.ImageWrapper(
         self.dropped_adjuster[0].astype('uint16')).save(f1)
     image_wrap.ImageWrapper(
         self.dropped_adjuster[1].astype('uint16')).save(f2)
     return f1, f2
示例#8
0
 def test_select_region(self):
     img = numpy.zeros((500, 500, 3), dtype='uint8')
     img_wrapper = image_wrap.ImageWrapper(img)
     selector = numpy.zeros((500, 500, 3), dtype='uint8')
     selector[30:40, 30:40, :] = [200, 200, 100]
     selector[130:140, 130:140, :] = [100, 200, 100]
     selector_wrapper = image_wrap.ImageWrapper(selector)
     result, rcolor = select_region(img_wrapper, selector_wrapper,
                                    convert_color('[200,200,100]'))
     result = result.to_array()
     self.assertTrue(numpy.all(result[30:40, 30:40, 3] == 255))
     self.assertTrue(numpy.all(result[130:140, 130:140, 3] == 0))
     self.assertEquals(rcolor, [200, 200, 100])
示例#9
0
    def test_float_images(self):
        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32))
        self.assertTrue(wrapper.to_float().to_array() is not None)

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32, 3),
                                          to_mask=True)
        self.assertTrue(wrapper.to_float().to_array() is not None)

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32), to_mask=True)
        self.assertTrue(wrapper.to_float().to_array() is not None)

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32, 3),
                                          to_mask=True)
        self.assertTrue(wrapper.to_float().to_array() is not None)
示例#10
0
 def test_all(self):
     img = numpy.zeros((500, 500), dtype='uint8')
     wrapper = image_wrap.ImageWrapper(img)
     filename = tempfile.mktemp(prefix='mstc', suffix='.png', dir='.')
     filename_output = tempfile.mktemp(prefix='mstcr',
                                       suffix='.png',
                                       dir='.')
     self.filesToKill.append(filename)
     wrapper.save(filename)
     self.filesToKill.append(filename_output)
     image_wrap.ImageWrapper(img).save(filename_output)
     self.no_snap_no_division(wrapper, filename, filename_output)
     self.no_snap_division(wrapper, filename, filename_output)
     self.snap_no_division(wrapper, filename, filename_output)
     self.snap_division(wrapper, filename, filename_output)
    def test_compare(self):
        from maskgen import tool_set
        wrapper1 = image_wrap.openImageFile(
            self.locateFile('tests/images/pre_blend.png'))
        arr2 = np.copy(wrapper1.image_array)
        for x in np.random.randint(1, arr2.shape[0] - 1, 100):
            for y in np.random.randint(1, arr2.shape[1] - 1, 100):
                arr2[x, y, 1] = arr2[x, y, 1] + np.random.randint(-20, 20)
        arr2[100:200, 100:200, 2] = arr2[100:200, 100:200, 2] - 25
        wrapper2 = image_wrap.ImageWrapper(arr2)

        args = [{
            'aggregate': 'luminance',
            'minimum threshold': 3,
            "weight": 4
        }, {
            'aggregate': 'luminance',
            'minimum threshold': 3,
            "weight": 1
        }, {
            'aggregate': 'max'
        }]
        for arg in args:
            result = tool_set.mediatedCompare(
                wrapper1.to_array().astype('int16'),
                wrapper2.to_array().astype('int16'),
                arguments=arg)
            self.assertTrue(np.all(result[0][100:200, 100:200] == 255))
            result[0][100:200, 100:200] = 0
            self.assertTrue(np.all(result[0] == 0))
示例#12
0
 def test_something(self):
     filename = self.locateFile('tests/images/test_project1.jpg')
     wrapper = image_wrap.openImageFile(filename)
     filename_output = tempfile.mktemp(prefix='mstcr',
                                       suffix='.png',
                                       dir='.')
     self.addFileToRemove(filename_output)
     img = numpy.asarray(wrapper)
     image_wrap.ImageWrapper(img).save(filename_output)
     args, error = plugins.callPlugin('WienerFilter',
                                      wrapper,
                                      filename,
                                      filename_output,
                                      percentageChange=0.5)
     wrapper = image_wrap.openImageFile(filename_output)
     output = wrapper.to_array()
     self.assertEqual(output.shape, img.shape)
     diff = abs(output - img)
     finaldiff = numpy.zeros((diff.shape[0], diff.shape[1]))
     for i in range(3):
         finaldiff = finaldiff + diff[:, :, i]
     finaldiff[finaldiff > 0] = 1
     self.assertTrue(
         sum(sum(finaldiff)) /
         (finaldiff.shape[0] * finaldiff.shape[1]) > 0.8)
示例#13
0
def select_region(img, mask, color=None):
    """
    Given a color mask and image and a given color,
    create an alpha channel on the given image, exposing only the regions
    associated with the color mask matching the given color.
    If the color is not provided, choose one of the available colors in the mask.
    Return the RGBA image and the color.
    :param img:
    :param mask:
    :return:
    @type img: image_wrap.ImageWrapper
    @type mask: image_wrap.ImageWrapper
    """
    rgba = img.convert('RGBA').to_array()
    mask = mask.to_array()
    channel = np.zeros((mask.shape[0], mask.shape[1])).astype('uint8')
    if color is None or color == 'None':
        colors = np.unique(
            np.vstack(mask).view([('', mask.dtype)] *
                                 np.prod(np.vstack(mask).shape[1])))
        colors = [color for color in colors.tolist()]
        colors.remove((0, 0, 0))
        color = colors[np.random.randint(0, len(colors) - 1)]

    channel[np.all(mask == [color[0], color[1], color[2]], axis=2)] = 255
    (contours, _) = cv2api.findContours(channel.copy(), cv2.RETR_LIST,
                                        cv2.CHAIN_APPROX_SIMPLE)
    for cnt in contours:
        if len(cnt) > 3:
            channel = np.zeros((mask.shape[0], mask.shape[1])).astype('uint8')
            cv2.fillConvexPoly(channel, cnt, 255)
            break
    rgba[:, :, 3] = channel
    return image_wrap.ImageWrapper(rgba), color
示例#14
0
    def test_rgb(self):
        filename = self.locateFile('tests/images/test_project5.jpg')
        img_wrapper = image_wrap.openImageFile(filename)
        img = img_wrapper.to_array()
        target_wrapper = image_wrap.ImageWrapper(img)
        filename_output = tempfile.mktemp(prefix='mstcr',
                                          suffix='.png',
                                          dir='.')
        self.filesToKill.extend([filename_output])
        target_wrapper.save(filename_output)

        args, error = plugins.callPlugin('SelectRegion',
                                         img_wrapper,
                                         filename,
                                         filename_output,
                                         alpha='yes')
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()
        self.assertTrue(sum(sum(output[:, :, 3])) > 255)
        x, y, w, h = widthandheight(output[:, :, 3])
        if x > 1:
            self.assertTrue(sum(sum(output[:, 0:x - 1, 3])) == 0)
        if y > 1:
            self.assertTrue(sum(sum(output[0:y - 1, :, 3])) == 0)
        self.assertTrue(sum(sum(output[y + h + 1:, x + w + 1:, 3])) == 0)
        self.assertEqual(output.shape[0], img.shape[0])
        self.assertEqual(output.shape[1], img.shape[1])
        self.assertTrue('paste_x' in args and args['paste_x'] > 0)
        self.assertTrue('paste_y' in args and args['paste_y'] > 0)
示例#15
0
    def test_resize_images_with_save(self):
        wrapper = image_wrap.ImageWrapper(
            np.random.randint(0, 64444, (256, 300), dtype='uint16'))
        self.assertTrue(
            wrapper.resize((250, 250), Image.ANTIALIAS).size[1] == 250)
        self.check_save(wrapper, 'TIFF')

        wrapper = image_wrap.ImageWrapper(
            np.random.randint(0, 64444, (256, 300, 3), dtype='uint16'))
        self.assertTrue(
            wrapper.resize((250, 250), Image.ANTIALIAS).size[1] == 250)
        self.check_save(wrapper, 'TIFF')

        wrapper = image_wrap.ImageWrapper(
            np.random.randint(0, 255, (256, 300), dtype='uint8'))
        self.assertTrue(
            wrapper.resize((250, 250), Image.ANTIALIAS).size[1] == 250)
        self.check_save(wrapper, 'PNG')
示例#16
0
    def test_mask_images(self):
        wrapper = image_wrap.ImageWrapper(
            np.random.randint(0, 64444, (32, 32), dtype='uint16'))
        self.assertEqual(wrapper.to_mask().mode, 'L')

        wrapper = image_wrap.ImageWrapper(np.random.randint(0,
                                                            64444, (32, 32, 3),
                                                            dtype='uint16'),
                                          to_mask=False)
        self.assertEqual(wrapper.to_mask().mode, 'L')

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32),
                                          to_mask=False)
        self.assertEqual(wrapper.to_mask().mode, 'L')

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32, 3),
                                          to_mask=False)
        self.assertEqual(wrapper.to_mask().mode, 'L')
示例#17
0
 def test_something(self):
     img = numpy.random.randint(0, 255, (500, 500, 3), dtype='uint8')
     img_wrapper = image_wrap.ImageWrapper(img)
     target_wrapper = image_wrap.ImageWrapper(
         numpy.zeros((500, 500, 3), dtype=numpy.uint8))
     filename = tempfile.mktemp(prefix='cstc', suffix='.png', dir='.')
     filename_output = tempfile.mktemp(prefix='cstcr',
                                       suffix='.png',
                                       dir='.')
     self.filesToKill.extend([filename, filename_output])
     img_wrapper.save(filename)
     target_wrapper.save(filename_output)
     op = plugins.getOperation('OutputPNG::Foo')
     self.assertEqual('OutputPng::Foo', op['name'])
     args, error = plugins.callPlugin('OutputPNG::Foo', img_wrapper,
                                      filename, filename_output)
     wrapper = image_wrap.openImageFile(filename_output)
     output = wrapper.to_array()
     self.assertTrue(numpy.all(img == output))
示例#18
0
    def test_snap(self):
        img = numpy.zeros((500,540),dtype='uint8')
        wrapper = image_wrap.ImageWrapper(img)
        filename  = tempfile.mktemp(prefix='mstc',suffix='.png',dir='.')
        filename_output = tempfile.mktemp(prefix='mstcr', suffix='.png', dir='.')
        self.filesToKill.append(filename)
        wrapper.save(filename)
        self.filesToKill.append(filename_output)
        image_wrap.ImageWrapper(img).save(filename_output)
        args,error = plugins.callPlugin('CV2ResizeByPercent',
                            wrapper,
                           filename,
                           filename_output,
                           percentage_width = 0.9,
                           percentage_height=0.9,
                            interpolation='other' )
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()

        self.assertEqual((448,480),output.shape)
示例#19
0
    def test_gray(self):
        img_wrapper = image_wrap.openImageFile(
            self.locateFile('tests/images/test_project5.jpg'))
        img = img_wrapper.to_array()
        img_wrapper = image_wrap.ImageWrapper(img)
        target_wrapper = image_wrap.ImageWrapper(img)
        filename = self.locateFile('tests/images/test_project5.jpg')
        filename_output = tempfile.mktemp(prefix='mstcr',
                                          suffix='.jpg',
                                          dir='.')
        self.filesToKill.extend([filename_output])
        target_wrapper.save(filename_output, format='JPEG')

        args, error = plugins.callPlugin('ExifGPSChange', img_wrapper,
                                         filename, filename_output)
        self.assertEqual(error, None)
        data = exif.getexif(filename)
        data_output = exif.getexif(filename_output)
        self.assertTrue(data['GPS Latitude'] != data_output['GPS Latitude'])
        self.assertTrue(data['GPS Longitude'] != data_output['GPS Longitude'])
示例#20
0
    def test_L_images(self):
        wrapper = image_wrap.ImageWrapper(
            np.random.randint(0, 64444, (32, 32), dtype='uint16'))
        self.assertTrue(wrapper.to_image() is not None)
        self.assertEqual(wrapper.mode, 'L')

        wrapper = image_wrap.ImageWrapper(np.random.randint(0,
                                                            64444, (32, 32, 3),
                                                            dtype='uint16'),
                                          to_mask=True)
        self.assertTrue(wrapper.to_image() is not None)
        self.assertEqual(wrapper.mode, 'L')

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32), to_mask=True)
        self.assertTrue(wrapper.to_image() is not None)
        self.assertEqual(wrapper.mode, 'L')

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32, 3),
                                          to_mask=True)
        self.assertTrue(wrapper.to_image() is not None)
        self.assertEqual(wrapper.mode, 'L')
示例#21
0
    def test_boundary(self):
        img = numpy.zeros((500, 540), dtype='uint8')
        wrapper = image_wrap.ImageWrapper(img)
        filename = tempfile.mktemp(prefix='mstc', suffix='.png', dir='.')
        filename_output = tempfile.mktemp(prefix='mstcr',
                                          suffix='.png',
                                          dir='.')
        self.filesToKill.append(filename)
        wrapper.save(filename)
        self.filesToKill.append(filename_output)
        image_wrap.ImageWrapper(img).save(filename_output)
        args, error = plugins.callPlugin('CropSelector',
                                         wrapper,
                                         filename,
                                         filename_output,
                                         percentage_width=0.001,
                                         percentage_height=0.0001,
                                         eightbit_boundary='yes')
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()

        img = numpy.zeros((500, 540), dtype='uint8')
        wrapper = image_wrap.ImageWrapper(img)
        filename = tempfile.mktemp(prefix='mstc', suffix='.png', dir='.')
        filename_output = tempfile.mktemp(prefix='mstcr',
                                          suffix='.png',
                                          dir='.')
        self.filesToKill.append(filename)
        wrapper.save(filename)
        self.filesToKill.append(filename_output)
        image_wrap.ImageWrapper(img).save(filename_output)
        args, error = plugins.callPlugin('CropSelector',
                                         wrapper,
                                         filename,
                                         filename_output,
                                         percentage_width=1,
                                         percentage_height=0.0001,
                                         eightbit_boundary='yes')
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()
示例#22
0
    def test_something(self):
        img = numpy.random.randint(0, 255, (500, 500, 3), dtype='uint8')
        img_wrapper = image_wrap.ImageWrapper(img)
        target_wrapper = image_wrap.ImageWrapper(img)
        filename = tempfile.mktemp(prefix='cstc', suffix='.png', dir='.')
        filename_output = tempfile.mktemp(prefix='cstcr', suffix='.png', dir='.')
        self.filesToKill.extend([filename, filename_output])
        img_wrapper.save(filename)
        target_wrapper.save(filename_output)

        args, error = plugins.callPlugin('Crop',
                                         img_wrapper,
                                         filename,
                                         filename_output,
                                         pixel_width=50,
                                         pixel_height=50,
                                         crop_x=7,
                                         crop_y=15)
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()
        self.assertTrue(output.shape == (450,450,3))
        self.assertTrue(numpy.all(output[0:10,0:10]==  img[15:25,7:17]))
示例#23
0
    def test_something(self):
        img = numpy.random.randint(0, 255, (500, 400, 3), dtype='uint8')
        img_wrapper = image_wrap.ImageWrapper(img)
        target_wrapper = image_wrap.ImageWrapper(img)
        filename = tempfile.mktemp(prefix='cstc', suffix='.png', dir='.')
        filename_output = tempfile.mktemp(prefix='cstcr',
                                          suffix='.png',
                                          dir='.')
        self.filesToKill.extend([filename, filename_output])
        img_wrapper.save(filename)
        target_wrapper.save(filename_output)

        args, error = plugins.callPlugin('CV2Resize',
                                         img_wrapper,
                                         filename,
                                         filename_output,
                                         width=550,
                                         height=450,
                                         interpolation='cubic')
        wrapper = image_wrap.openImageFile(filename_output)
        output = wrapper.to_array()
        self.assertTrue(output.shape == (450, 550, 3))
示例#24
0
    def test_resize_images(self):
        wrapper = image_wrap.ImageWrapper(
            np.random.randint(0, 64444, (32, 32), dtype='uint16'))
        self.assertEqual(
            wrapper.resize((40, 40), Image.ANTIALIAS).size, (40, 40))

        wrapper = image_wrap.ImageWrapper(np.random.randint(0,
                                                            64444, (32, 32, 3),
                                                            dtype='uint16'),
                                          to_mask=False)
        self.assertEqual(
            wrapper.resize((40, 40), Image.ANTIALIAS).size, (40, 40))

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32),
                                          to_mask=False)
        self.assertEqual(
            wrapper.resize((40, 40), Image.ANTIALIAS).size, (40, 40))

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32, 3),
                                          to_mask=False)
        self.assertEqual(
            wrapper.resize((40, 40), Image.ANTIALIAS).size, (40, 40))
示例#25
0
    def test_convert_images(self):
        wrapper = image_wrap.ImageWrapper(
            np.random.randint(0, 64444, (32, 32), dtype='uint16'))
        self.assertEqual(
            wrapper.convert("RGBA").image_array.shape, (32, 32, 4))

        wrapper = image_wrap.ImageWrapper(np.random.randint(0,
                                                            64444, (32, 32, 3),
                                                            dtype='uint16'),
                                          to_mask=False)
        self.assertEqual(
            wrapper.convert("RGBA").image_array.shape, (32, 32, 4))

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32),
                                          to_mask=False)
        self.assertEqual(
            wrapper.convert("RGBA").image_array.shape, (32, 32, 4))

        wrapper = image_wrap.ImageWrapper(np.random.rand(32, 32, 3),
                                          to_mask=False)
        self.assertEqual(
            wrapper.convert("RGBA").image_array.shape, (32, 32, 4))
示例#26
0
def transform(img, source, target, **kwargs):
    source_im = numpy.asarray(img)
    mask = tool_set.openImageFile(kwargs['inputmaskname']).to_mask()
    mask_array = numpy.asarray(mask)
    black_image = source_im.copy()
    new_im = source_im.copy()
    black_image[:, :] = (0, 0, 0)
    cv2.bitwise_and(source_im, black_image, new_im, mask_array)
    save_im = image_wrap.ImageWrapper(new_im)
    maskfd, maskfile = tempfile.mkstemp(suffix='.png')
    os.close(maskfd)
    save_im.save(maskfile)
    target_im = None
    try:
        lqrCommandLine = [
            'gmic', maskfile, '-gimp_inpaint_patchmatch',
            ' 0,9,10,5,1,0,0,0,0,3,0', '-o', target
        ]
        pcommand = subprocess.Popen(" ".join(lqrCommandLine),
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
        stdout, stderr = pcommand.communicate()
        if pcommand.returncode == 0:
            target_im = numpy.asarray(tool_set.openImageFile(target))
        else:
            logging.getLogger('maskgen').error(
                'Failure of Remove (inpainting) plugin {}'.format(str(stderr)))
    except Exception as e:
        logging.getLogger('maskgen').error(
            'Failure of Remove (inpainting) plugin {}'.format(str(e)))
    os.remove(maskfile)
    if target_im is None:
        target_im = cv2.inpaint(source_im, mask_array, 3, cv2.INPAINT_TELEA)
    save_im = image_wrap.ImageWrapper(target_im)
    save_im.save(target)
    return {'purpose': 'remove'}, None
示例#27
0
    def test_something(self):
        img_wrapper = image_wrap.openImageFile(
            self.locateFile('tests/images/test.tif'))
        img = img_wrapper.to_array()
        img_wrapper = image_wrap.ImageWrapper(img)
        target_wrapper = image_wrap.ImageWrapper(img)
        filename = self.locateFile('tests/images/test.tif')
        filename_output = tempfile.mktemp(prefix='mstcr',
                                          suffix='.png',
                                          dir='.')
        self.filesToKill.extend([filename_output])
        target_wrapper.save(filename_output)

        args, error = plugins.callPlugin(
            'ImageSizeSelector',
            img_wrapper,
            filename,
            filename_output,
            cameraDataFile=self.locateFile('data/camera_sizes.json'),
            pickOne='yes',
        )

        self.assertTrue('height' in args and args['height'] == 3264)
        self.assertTrue('width' in args and args['width'] == 4928)
示例#28
0
def transform(img, source, target, **kwargs):
    mask = numpy.asarray(
        tool_set.openImageFile(kwargs['inputmaskname']).to_mask())
    source_im = numpy.asarray(tool_set.openImageFile(source))
    paste_x = int(kwargs['paste_x'])
    paste_y = int(kwargs['paste_y'])
    x, y, w, h = widthandheight(mask)
    w += w % 2
    h += h % 2
    image_to_cover = numpy.copy(source_im)
    flipped_mask = 255 - mask
    for c in range(0, source_im.shape[2]):
        image_to_cover[paste_y:paste_y + h, paste_x:paste_x + w, c] = \
            image_to_cover[paste_y:paste_y + h, paste_x:paste_x + w, c] * \
            (flipped_mask[y:y + h, x:x + w] / 255) + \
            image_to_cover[y:y + h, x:x + w, c] * \
            (mask[y:y + h, x:x + w] / 255)
    target_im = image_wrap.ImageWrapper(image_to_cover)
    target_im.save(target)
    return {'purpose': 'clone'}, None
示例#29
0
 def test_something(self):
     img = numpy.zeros((500,500),dtype='uint8')
     wrapper = image_wrap.ImageWrapper(img)
     filename  = tempfile.mktemp(prefix='mstc',suffix='.png',dir='.')
     filename_output = tempfile.mktemp(prefix='mstcr', suffix='.png', dir='.')
     self.filesToKill.append(filename)
     wrapper.save(filename)
     self.filesToKill.append(filename_output)
     wrapper.save(filename_output)
     args,error = plugins.callPlugin('MaskSelector',
                         wrapper,
                        filename,
                        filename_output,
                        percentage_width = 0.1,
                         percentage_height=0.1)
     wrapper = image_wrap.openImageFile(filename_output)
     output = wrapper.to_array()
     self.assertTrue(sum(sum(output))>255)
     self.assertTrue(sum(sum(output)) < numpy.prod(output.shape))
     self.assertEqual(output.shape, img.shape)
     self.assertTrue('paste_x' in args and args['paste_x'] > 0)
     self.assertTrue('paste_y' in args and args['paste_y'] > 0)
示例#30
0
def transform(img,source,target,**kwargs):
    source_im = numpy.asarray(img)

    def toColorBalanceFromPercentage(val):
        return (float(val),1.0-(val))

    algorithm = MultiScaleResinexChromaPerservation if 'algorithm' in kwargs and \
                                                       kwargs['algorithm'] == 'Chroma Preserving' else MultiScaleResinexLab


    colorBalance = toColorBalanceFromPercentage(float(kwargs['color balance'])) if 'color balance' in kwargs else (0.01, 0.99)

    algorithm_instance = algorithm([15, 80, 125],
                                   G=30,
                                   b=-6,
                                   alpha=125.0,
                                   beta=1.0,
                                   colorBalance=colorBalance
                                   )
    image_wrap.ImageWrapper(algorithm_instance(source_im)).save(target)

    return None,None