示例#1
0
    def test_applyMask(self):
        expected = self.setup.getExpectedOutputMatrix(self._testMethodName)
        dft_image = self.setup.getInputMatrix('chaplin_dft.npy')
        mask = self.setup.getInputMatrix('mask.npy')

        self.actual = util.applyMask(dft_image, mask)
        self.assertTrue(self.setup.matrixEqual(expected, self.actual))
示例#2
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)
#mask_size2 = (h, w)
percent = .5

mask = sia.cartesianPattern(mask_size2, percent)

mask1 = sia.cartesianPattern(mask_size2, .05)
mask2 = sia.cartesianPattern(mask_size2, .15)
mask3 = sia.cartesianPattern(mask_size2, .35)
mask4 = sia.cartesianPattern(mask_size2, .64)

masks = (mask1, mask2, mask3, mask4)

count = 0
for mask in masks:
    a = util.applyMask(img_copy2, mask)
    b = util.writableDFT(a)
    c = util.normalizeImage(b)
    d = util.post_process_image(c)
    count += 1
    print(count)
    util.displayImage(d)

##############  Part 4  #####################

#change img(heart) to img2(brain)
# img_copy = util.getDFT(img2)
# rays = (1, 15, 50, 100, 360)
#
# mask = sia.radialPattern(mask_size2, rays[0])
#
write_dft = util.writableDFT(dft_cardiac)
util.saveMatrix("Cardiac_DFT.jpg", write_dft)
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)
#util.saveMatrix("Brain_DFT.jpg", dft_brain)
height, width = brain.shape
brain_size = np.array([height, width])

p1mask = aqc.bandPattern(cardiac_size, 15, 128, 35)
p1fmask = util.post_process_image(p1mask)
util.saveImage("p1fmask.jpg", p1fmask)
p1applied = util.applyMask(dft_cardiac, p1mask)
p1image = util.getImage(p1applied)
p1fimage = util.post_process_image(p1image)
util.saveImage('p1_Masked_Image.jpg', p1fimage)

p2mask1 = aqc.bandPattern(cardiac_size, 15, 128, 10)
p2applied1 = util.applyMask(dft_cardiac, p2mask1)
p2image1 = util.getImage(p2applied1)
p2fimage1 = util.post_process_image(p2image1)
util.saveImage("p2_Masked_Image_1.jpg", p2fimage1)

p2mask2 = aqc.bandPattern(cardiac_size, 10, 171, 135)
p2applied2 = util.applyMask(dft_cardiac, p2mask2)
p2image2 = util.getImage(p2applied2)
p2fimage2 = util.post_process_image(p2image2)
util.saveImage("p2_Masked_Image_2.jpg", p2fimage2)
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"
    util.saveImage(filename, p7lfimage)