# Use this file as you wish to generate the images needed to answer the report
import src.project.Utilities as util
import src.project.ImageSynthesisNoise as isn
import cv2
import numpy as np

# image = util.loadImage('images/brain.png')
matrix = util.loadMatrix('images/noisyimage.npy')
rows, cols = matrix.shape
mask = isn.gaussianLowpassFilter((rows, cols), cutoff=40)
im = np.multiply(matrix, mask)
im = util.post_process_images(util.getImage(im))

# im = np.abs(matrix)
# im = util.post_process_images(im)
# rows, cols = image.shape

util.displayImage(im)

# mask = isn.butterworthLowpassFilter((rows, cols), cutoff=40, order=7)
# mask = isn.gaussianHighpassFilter((rows, cols), cutoff=150)

# shift_fft = util.getDFT(image)
# filtered_image_fft = np.multiply(mask, shift_fft)
# filtered_image = util.post_process_images(util.getImage(filtered_image_fft))

# util.saveImage('butterworthLowpassFilter.png', filtered_image)
# print(util.signalToNoise(filtered_image))

# util.displayImage(filtered_image)
normal_cardiac = util.normalizeImage(cardiac)
dft_cardiac = util.getDFT(normal_cardiac)
height, width = cardiac.shape
cardiac_size = np.array([height, width])

brain = util.loadImage("images/brain.png")
normal_brain = util.normalizeImage(brain)
dft_brain = util.getDFT(normal_brain)
height, width = brain.shape
brain_size = np.array([height, width])

cutoff = np.array([5, 20, 45, 60])
order = np.array([1, 2, 3, 4])
for i in cutoff:
    for j in order:
        p6mask = noise.butterworthLowpassFilter(brain_size, i, j)
        p6applied = util.applyMask(dft_brain, p6mask)
        p6image = util.getImage(p6applied)
        p6fimage = util.post_process_image(p6image)
        filename = "p6_Masked_Image_" + str(i) + "_" + str(j) + ".jpg"
        snr_p6 = util.signalToNoise(brain, p6fimage)
        print(filename, snr_p6)
        util.saveImage(filename, p6fimage)

glhp = np.array([200, 40, 120, 10])
for k in glhp:
    p7lmask = noise.gaussianLowpassFilter(brain_size, k)
    p7lapplied = util.applyMask(dft_brain, p7lmask)
    p7limage = util.getImage(p7lapplied)
    p7lfimage = util.post_process_image(p7limage)
    filename = "p7_GLP_Masked_Image_" + str(k) + ".jpg"
Exemple #3
0
# count = 0
# for cut in cutout:
#     print(cut)
#     mask = isn.gaussianHighpassFilter(mask_size2, cut)
#     a = util.applyMask(img_copy, mask)
#     b = util.writableDFT(a)
#     c = util.normalizeImage(b)
#     d = util.post_process_image(c)
#     count += 1
#     print(count)
#     util.displayImage(d)

nmask_size = (h2, w2)

img_copy = util.getImage(img3)

mask = isn.idealHighpassFilter(nmask_size, 100)
mask1 = isn.idealLowpassFilter(nmask_size, 100)
mask2 = isn.gaussianHighpassFilter(nmask_size, 100)
mask3 = isn.ringLowpassFilter(nmask_size, 100, 10)
mask4 = isn.butterworthHighpassFilter(nmask_size, 50, 2)

masks = (mask, mask1, mask2, mask3, mask4)

count = 0
for mask in masks:
    a = util.applyMask(mask, img_copy)
    count += 1
    print(count)
    util.displayImage(a)
 def test_ringLowpassFilter_half_thin_ring(self):
     expected = self.setup.getExpectedOutput(self._testMethodName)
     self.actual = noise.ringLowpassFilter(self.emptymask, 50, 3)
     self.actual = self.setup.normalizeImage(self.actual)
     self.assertTrue(self.setup.imagesEqual(expected, self.actual))
 def test_gaussianHighpassFilter_half_width(self):
     expected = self.setup.getExpectedOutput(self._testMethodName)
     self.actual = noise.gaussianHighpassFilter(self.emptymask, 100)
     self.actual = self.setup.normalizeImage(self.actual)
     self.assertTrue(self.setup.imagesEqual(expected, self.actual))
 def test_butterworthHighpassFilter_high_width_high_order(self):
     expected = self.setup.getExpectedOutput(self._testMethodName)
     self.actual = noise.butterworthHighpassFilter(self.emptymask, 50, 3)
     self.actual = self.setup.normalizeImage(self.actual)
     self.assertTrue(self.setup.imagesEqual(expected, self.actual))
 def test_idealLowpassFilter_high_width(self):
     expected = self.setup.getExpectedOutput(self._testMethodName)
     self.actual = noise.idealLowpassFilter(self.emptymask, 150)
     self.actual = self.setup.normalizeImage(self.actual)
     self.assertTrue(self.setup.imagesEqual(expected, self.actual))
 def test_ringHighpassFilter_large_thick_ring(self):
     expected = self.setup.getExpectedOutput(self._testMethodName)
     self.actual = noise.ringHighpassFilter(self.emptymask, 100, 10)
     self.actual = self.setup.normalizeImage(self.actual)
     self.assertTrue(self.setup.imagesEqual(expected, self.actual))