Exemple #1
0
    def test_read_tiff(self):
        """Test of TIFFReaderWriter reading"""
        srw = em2d.SpiderImageReaderWriter()
        trw = em2d.TIFFImageReaderWriter()
        fn_tif_img = self.get_input_file_name("lena-256x256.tif")
        tif_img = em2d.Image(fn_tif_img, trw)
        fn_spider_img = self.get_input_file_name("lena-256x256.spi")
        spider_img = em2d.Image(fn_spider_img, srw)
        rows = int(tif_img.get_header().get_number_of_rows())
        cols = int(tif_img.get_header().get_number_of_columns())

        self.assertEqual(spider_img.get_header().get_number_of_rows(), rows)
        self.assertEqual(spider_img.get_header().get_number_of_columns(), cols)
        ccc = em2d.get_cross_correlation_coefficient(tif_img.get_data(),
                                                     spider_img.get_data())
        self.assertAlmostEqual(ccc, 1, delta=0.01, msg="ccc ins not 1")
Exemple #2
0
 def test_write_tiff(self):
     """Test of TIFFReaderWriter writing"""
     trw = em2d.TIFFImageReaderWriter()
     srw = em2d.SpiderImageReaderWriter()
     fn_img1 = self.get_input_file_name("lena-256x256.tif")
     img1 = em2d.Image(fn_img1, trw)
     fn_img2 = "temp.tif"
     img1.write(fn_img2, trw)
     img2 = em2d.Image(fn_img2, trw)
     # Use the ccc for testing instead of the pixel values. The matrix
     # in img2 is transformed from floats to ints son it can be written.
     # Values can change, but the ccc has to be very close to 1.
     ccc = em2d.get_cross_correlation_coefficient(img1.get_data(),
                                                  img2.get_data())
     print ccc
     self.assertAlmostEqual(ccc, 1, delta=0.01,
                            msg="Written TIFF image is not equal to read ")
     os.remove(fn_img2)
Exemple #3
0
 def test_write_error_tiff(self):
     """Test that writing with TIFFReaderWriter fails with bad extension"""
     trw = em2d.TIFFImageReaderWriter()
     fn_img1 = self.get_input_file_name("lena-256x256.tif")
     img1 = em2d.Image(fn_img1, trw)
     self.assertRaises(IOError, img1.write, "temp.xxx", trw)
Exemple #4
0
## \example em2d/em_images_conversion.py
# Conversion of Electron Microscopy Images.
#

import IMP
import IMP.em2d as em2d
import os
"""
    Conversion of Electron Microscopy Images.

"""

# Read images
fn_selection = em2d.get_example_path("all-1z5s-projections.sel")

srw = em2d.SpiderImageReaderWriter()
trw = em2d.TIFFImageReaderWriter()
fn_images = em2d.read_selection_file(fn_selection)
fn_images = [em2d.get_example_path(x) for x in fn_images]
images = em2d.read_images(fn_images, srw)
# write
fn_saved = em2d.create_filenames(3, "1z5s-projection", "tif")
em2d.save_images(images, fn_saved, trw)