Beispiel #1
0
 def test_instantiation_from_shape_with_name(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50), name='test')
     self.assertEqual(image.name, 'test')
     self.assertEqual(len(image.history), 0)
     self.assertEqual(image.history.creation,
                      'Instantiated Image from shape (50, 50) as test')
Beispiel #2
0
 def test_instantiation_from_shape(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50))
     self.assertTrue(isinstance(image, np.ndarray))
     self.assertEqual(image.shape, (50, 50))
     self.assertEqual(len(image.history), 0)
     self.assertEqual(image.history.creation,
                      'Instantiated Image from shape (50, 50)')
Beispiel #3
0
    def test_png(self):
        from jicbioimage.core.image import Image
        image = Image((600, 500), dtype=np.uint64)
        png = image.png()

        ar = np.asarray(PIL.Image.open(io.BytesIO(png)))

        self.assertEqual(ar.shape[0], 600)
        self.assertEqual(ar.shape[1], 500)
Beispiel #4
0
    def test_png_with_width(self):
        from jicbioimage.core.image import Image
        image = Image((600, 800), dtype=np.uint64)
        thumbnail = image.png(width=300)

        ar = np.asarray(PIL.Image.open(io.BytesIO(thumbnail)))

        self.assertEqual(ar.shape[0], 300)
        self.assertEqual(ar.shape[1], 400)
    def test_repr_html(self):
        from jicbioimage.core.image import ImageCollection, ProxyImage, Image
        image_collection = ImageCollection()
        image = Image((50,50))
        image.png = MagicMock(return_value=bytearray('image', encoding='utf-8'))
        with patch('jicbioimage.core.image.Image.from_file', return_value=image) as patched_image:
            image_collection.append(ProxyImage('test0.tif'))
            html = image_collection._repr_html_()
            self.assertEqual(html.strip().replace(' ', '').replace('\n', ''),
'''
<div style="float: left; padding: 2px;" >
    <p>
        <table><tr><th>Index</th><td>0</td></tr></table>
    </p>
    <img style="margin-left: auto; margin-right: auto;" src="data:image/png;base64,aW1hZ2U=" />
</div>
'''.strip().replace(' ', '').replace('\n', ''))

        image.png.assert_called_once_with(width=300)
Beispiel #6
0
    def test_repr_html(self):
        from jicbioimage.core.image import MicroscopyCollection, MicroscopyImage, Image
        microscopy_collection = MicroscopyCollection()
        image = Image((50, 50))
        image.png = MagicMock(
            return_value=bytearray('image', encoding='utf-8'))
        with patch('jicbioimage.core.image.Image.from_file',
                   return_value=image) as patched_image:
            microscopy_collection.append(
                MicroscopyImage(
                    'test0.tif',
                    dict(series=1, channel=2, zslice=3, timepoint=4)))
            html = microscopy_collection._repr_html_()
            self.assertEqual(
                html.strip().replace(' ', '').replace('\n', ''), '''
<div style="float: left; padding: 2px;" >
    <p>
        <table>
            <tr>
                <th>Index</th>
                <th>Series</th>
                <th>Channel</th>
                <th>Z-slice</th>
                <th>Time point</th>
            </tr>
            <tr>
                <td>0</td>
                <td>1</td>
                <td>2</td>
                <td>3</td>
                <td>4</td>
            </tr>
        </table>
    </p>
    <img style="margin-left: auto; margin-right: auto;" src="data:image/png;base64,aW1hZ2U=" />
</div>
'''.strip().replace(' ', '').replace('\n', ''))
Beispiel #7
0
 def test_png_converts_to_uint8(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50), dtype=np.uint64)
     # The below raises error if the image is not converted to uint8
     # before returning the png string.
     png = image.png
Beispiel #8
0
 def test_png_attr(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50))
     self.assertTrue(hasattr(image, 'png'))
Beispiel #9
0
 def test_repr_png_callable(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50))
     self.assertTrue(callable(image._repr_png_))
Beispiel #10
0
 def test_default_name(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50))
     self.assertTrue(image.name is None)
Beispiel #11
0
 def test_default_type(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50))
     self.assertEqual(image.dtype, np.uint8,
                      'Image type not np.uint8 but {}'.format(image.dtype))
Beispiel #12
0
 def test_rgb_instantiation_from_shape(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50, 3))
     self.assertEqual(image.shape, (50, 50, 3))
Beispiel #13
0
 def test_instantiation_from_shape_no_history(self):
     from jicbioimage.core.image import Image
     image = Image((50, 50), log_in_history=False)
     self.assertEqual(len(image.history), 0)
Beispiel #14
0
 def test_repr(self):
     from jicbioimage.core.image import Image
     im = Image((50, 50))
     pos = hex(id(im))
     expected = "<Image object at {}, dtype=uint8>".format(pos)
     self.assertEqual(repr(im), expected)