Example #1
0
    def test_calculate_mean_spectrum(self):

        mani.calculate_mean_spectrum(self.specialmsi)

        np.testing.assert_equal(np.array([0.96, 2., 3.04, 4.08, 5.12]),
                                self.specialmsi.get_image(),
                        "mean spectrum is correctly calculated on image with " +
                        "no mask applied")
Example #2
0
    def test_calculate_mean_spectrum_masked_image(self):

        mani.apply_segmentation(self.specialmsi, self.segmentation)
        mani.calculate_mean_spectrum(self.specialmsi)

        np.testing.assert_equal(self.specialValue, self.specialmsi.get_image(),
                        "mean spectrum is correctly calculated on image with " +
                        "mask applied")
Example #3
0
    def test_calculate_mean_spectrum_masked_image(self):

        mani.apply_segmentation(self.specialmsi, self.segmentation)
        mani.calculate_mean_spectrum(self.specialmsi)

        np.testing.assert_equal(self.specialValue, self.specialmsi.get_image(),
                        "mean spectrum is correctly calculated on image with " +
                        "mask applied")
Example #4
0
    def test_calculate_mean_spectrum(self):

        mani.calculate_mean_spectrum(self.specialmsi)

        np.testing.assert_equal(np.array([0.96, 2., 3.04, 4.08, 5.12]),
                                self.specialmsi.get_image(),
                        "mean spectrum is correctly calculated on image with " +
                        "no mask applied")
    def test_write_one_d_image_works(self):
        writer = NrrdWriter(self.msi)
        msimani.calculate_mean_spectrum(self.msi)
        writer.write(self.fileUriToWrite)

        reader = NrrdReader()
        msi = reader.read(self.fileUriToWrite)
        np.testing.assert_array_equal(msi.get_image(),
                                      np.array([1, 2, 3, 4, 5]),
                                      "1d image correctly written and read")
Example #6
0
    def test_write_one_d_image_works(self):
        writer = NrrdWriter(self.msi)
        msimani.calculate_mean_spectrum(self.msi)
        writer.write(self.fileUriToWrite)

        reader = NrrdReader()
        msi = reader.read(self.fileUriToWrite)
        np.testing.assert_array_equal(msi.get_image(),
                                      np.array([1, 2, 3, 4, 5]),
                                      "1d image correctly written and read")
Example #7
0
    def test_flatfield_correction_with_single_value(self):
        desired_image_data = np.ones_like(self.msi.get_image())
        flatfield = copy.copy(self.msi)
        mani.calculate_mean_spectrum(flatfield)
        unchanged_flatfield = copy.deepcopy(flatfield)

        mani.flatfield_correction(self.msi, flatfield)

        np.testing.assert_equal(self.msi.get_image(),
                                       desired_image_data,
                "flatfield correctly accounted for from singular reference value")
        np.testing.assert_equal(flatfield, unchanged_flatfield,
                "flatfield not changed by algorithm")
Example #8
0
    def test_flatfield_correction_with_single_value(self):
        desired_image_data = np.ones_like(self.msi.get_image())
        flatfield = copy.copy(self.msi)
        mani.calculate_mean_spectrum(flatfield)
        unchanged_flatfield = copy.deepcopy(flatfield)

        mani.flatfield_correction(self.msi, flatfield)

        np.testing.assert_equal(self.msi.get_image(),
                                       desired_image_data,
                "flatfield correctly accounted for from singular reference value")
        np.testing.assert_equal(flatfield, unchanged_flatfield,
                "flatfield not changed by algorithm")
Example #9
0
    def test_dark_correction_with_single_value(self):
        desired_image_data = copy.copy(self.specialmsi.get_image())
        desired_image_data -= 1

        dark = copy.copy(self.specialmsi)
        dark.set_image(np.ones_like(dark.get_image()))
        mani.calculate_mean_spectrum(dark)

        mani.dark_correction(self.specialmsi, dark)

        np.testing.assert_equal(self.specialmsi.get_image(),
                                       desired_image_data,
                "dark image correctly accounted for from singular dark value")
        np.testing.assert_equal(dark.get_image(),
                                       np.ones_like(dark.get_image()),
                "dark image unchanged by dark correction")
Example #10
0
    def test_dark_correction_with_single_value(self):
        desired_image_data = copy.copy(self.specialmsi.get_image())
        desired_image_data -= 1

        dark = copy.copy(self.specialmsi)
        dark.set_image(np.ones_like(dark.get_image()))
        mani.calculate_mean_spectrum(dark)

        mani.dark_correction(self.specialmsi, dark)

        np.testing.assert_equal(self.specialmsi.get_image(),
                                       desired_image_data,
                "dark image correctly accounted for from singular dark value")
        np.testing.assert_equal(dark.get_image(),
                                       np.ones_like(dark.get_image()),
                "dark image unchanged by dark correction")
Example #11
0
    def run(self):
        tiff_ring_reader = TiffRingReader()
        nr_filters = len(sc.other["RECORDED_WAVELENGTHS"])

        # analyze all the first image files
        image_files = get_image_files_from_folder(self.dark_folder,
                                                  suffix="F0.tiff")

        # returns the mean dark image vector of all inputted dark image
        # overly complicated TODO SW: make this simple code readable.
        dark_means = map(
            lambda image_name: msimani.calculate_mean_spectrum(
                tiff_ring_reader.read(
                    os.path.join(self.dark_folder, image_name), nr_filters)[0]
            ), image_files)
        dark_means_sum = reduce(lambda x, y: x + y.get_image(), dark_means, 0)
        final_dark_mean = dark_means_sum / len(dark_means)

        msi = Msi(image=final_dark_mean)
        msi.set_wavelengths(sc.other["RECORDED_WAVELENGTHS"])

        # write flatfield as nrrd
        writer = NrrdWriter(msi)
        writer.write(self.output().path)
Example #12
0
    def run(self):
        tiff_ring_reader = TiffRingReader()
        nr_filters = len(sc.other["RECORDED_WAVELENGTHS"])

        # analyze all the first image files
        image_files = get_image_files_from_folder(self.dark_folder,
                                                  suffix="F0.tiff")

        # returns the mean dark image vector of all inputted dark image
        # overly complicated TODO SW: make this simple code readable.
        dark_means = map(lambda image_name:
                            msimani.calculate_mean_spectrum(
                                tiff_ring_reader.read(os.path.join(self.dark_folder, image_name),
                                                      nr_filters)[0]),
                         image_files)
        dark_means_sum = reduce(lambda x, y: x+y.get_image(), dark_means, 0)
        final_dark_mean = dark_means_sum / len(dark_means)

        msi = Msi(image=final_dark_mean)
        msi.set_wavelengths(sc.other["RECORDED_WAVELENGTHS"])

        # write flatfield as nrrd
        writer = NrrdWriter(msi)
        writer.write(self.output().path)