I don't why I cannot to find the correct solution to achieve my goal, removing sub-swath noise in Sentinel-1 HV polarization imagery. I’ve tried as my best in StackOverflow website and CSDN in Chinese. But, those efforts are meaningless. I still don't know how to using FFT in python to get my succeed.
I've referred to these website(https://stackoverflow.com/questions/38476359/fft-on-image-with-python , https://stackoverflow.com/questions/32951036/opencv-python-mask-on-fftimage-why-do-we-need-two-channels ) and some PPT on introducing Fourier Transformation. Besides, I get five steps to make FFT, as following:
I've referred to these website(https://stackoverflow.com/questions/38476359/fft-on-image-with-python , https://stackoverflow.com/questions/32951036/opencv-python-mask-on-fftimage-why-do-we-need-two-channels ) and some PPT on introducing Fourier Transformation. Besides, I get five steps to make FFT, as following:
1.read
image
2.get
fft
of image --> f
3.crate
mask
4.multiply
f with mask --> g
5.get
inverse of g
My puzzle encountered in coding is how to put FFT apply to tiff format images, websites in above is for processing .jpg or .png format. Another question is when I found a sample demo about processing tif( Coding is given in the end of the article), I unexpectedly to find the result after FFT existed a fatal bug, data value of tiff image changed. Until now, I've wasted a week days in the begining of new semester of my master degree in the last year. Oh, my god!
I surrender and give up for this way. Maybe I won't remove boundary noise in S-1 HV images.
I surrender and give up for this way. Maybe I won't remove boundary noise in S-1 HV images.
Coding:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 04 14:12:09 2018
@author: Baikal
"""
import cv2
import scipy
import numpy as np
tif = cv2.imread( r'C:\Users\Baikal\Desktop\delete\Aim_Beta0_HV.tif', 2 )
rows, cols = tif.shape
## Get FFT imgage.
fft = np.fft.fft2( tif )
## Move to center
fftshift = np.fft.fftshift( fft )
## Create Mask tif file.
rowl = rows / 2 - 100
rowr = rows / 2 + 100
columnl = cols / 2 - 100
columnr = cols / 2 + 100
mask = np.ones( tif.shape, np.float32 )
for row in range( rowl, rowr ):
for col in range( columnl, columnr ):
mask[ row, col ] = 0
## Filter.
fftshift_mask = fftshift * mask
## Get inverse of fft.
ifft = np.fft.ifft2( np.fft.ifftshift( fftshift_mask ) )
# To show normally , to get abs of complex number(fft).
ifft_img = np.abs( ifft )
# Save FFT image to disk.
scipy.misc.imsave( 'ifft.tif', ifft_img )
- Original TIFF image(Data range below 0)
- FFT result(Data range from 0 to 255)
没有评论:
发表评论