def parpareparam(self): self.c = 3e8 self.width = self.wall_size / 2.0 self.bin_resolution = self.bin_len / self.c self.trange = self.crop * self.c * self.bin_resolution ########################################################3 temprol_grid = self.crop sptial_grid = self.spatial_grid wall_size = self.wall_size bin_resolution = self.bin_resolution sampling_coeff = self.sampling_coeff cycles = self.cycles ###################################################### # Step 0: define virtual wavelet properties # s_lamda_limit = wall_size / (sptial_grid - 1); # sample spacing on the wall # sampling_coeff = 2; # scale the size of the virtual wavelength (usually 2, optionally 3 for noisy scenes) # virtual_wavelength = sampling_coeff * (s_lamda_limit * 2); # virtual wavelength in units of cm # cycles = 5; # number of wave cycles in the wavelet, typically 4-6 s_lamda_limit = wall_size / (sptial_grid - 1) # sample spacing on the wall virtual_wavelength = sampling_coeff * (s_lamda_limit * 2) # virtual wavelength in units of cm self.virtual_wavelength = virtual_wavelength virtual_cos_wave_k, virtual_sin_wave_k = \ waveconvparam(bin_resolution, virtual_wavelength, cycles) virtual_cos_sin_wave_2xk = np.stack( [virtual_cos_wave_k, virtual_sin_wave_k], axis=0) # use pytorch conv to replace matlab conv self.virtual_cos_sin_wave_inv_2x1xk = torch.from_numpy( virtual_cos_sin_wave_2xk[:, ::-1].copy()).unsqueeze(1) ################################################### slope = self.width / self.trange psf = definePsf(sptial_grid, temprol_grid, slope) fpsf = np.fft.fftn(psf) # lct # invpsf = np.conjugate(fpsf) / (1 / self.snr + np.real(fpsf) ** 2 + np.imag(fpsf) ** 2) # bp invpsf = np.conjugate(fpsf) self.invpsf_real = torch.from_numpy( np.real(invpsf).astype(np.float32)).unsqueeze(0) self.invpsf_imag = torch.from_numpy( np.imag(invpsf).astype(np.float32)).unsqueeze(0) ###################################################### mtx_MxM, mtxi_MxM = resamplingOperator(temprol_grid) self.mtx_MxM = torch.from_numpy(mtx_MxM.astype(np.float32)) self.mtxi_MxM = torch.from_numpy(mtxi_MxM.astype(np.float32))
def parpareparam(self): self.c = 3e8 self.width = self.wall_size / 2.0 self.bin_resolution = self.bin_len / self.c self.trange = self.crop * self.c * self.bin_resolution # maybe learnable? self.snr = 1e-1 ########################################################3 temprol_grid = self.crop sptial_grid = self.spatial_grid # 0-1 gridz_M = np.arange(temprol_grid, dtype=np.float32) gridz_M = gridz_M / (temprol_grid - 1) gridz_1xMx1x1 = gridz_M.reshape(1, -1, 1, 1) self.gridz_1xMx1x1 = torch.from_numpy(gridz_1xMx1x1.astype(np.float32)) ################################################### slope = self.width / self.trange psf = definePsf(sptial_grid, temprol_grid, slope) fpsf = np.fft.fftn(psf) if self.method == 'lct': invpsf = np.conjugate(fpsf) / (1 / self.snr + np.real(fpsf)**2 + np.imag(fpsf)**2) elif self.method == 'bp': invpsf = np.conjugate(fpsf) self.invpsf_real = torch.from_numpy( np.real(invpsf).astype(np.float32)).unsqueeze(0) self.invpsf_imag = torch.from_numpy( np.imag(invpsf).astype(np.float32)).unsqueeze(0) ###################################################### mtx_MxM, mtxi_MxM = resamplingOperator(temprol_grid) self.mtx_MxM = torch.from_numpy(mtx_MxM.astype(np.float32)) self.mtxi_MxM = torch.from_numpy(mtxi_MxM.astype(np.float32)) ############################################################# if self.method == 'bp': lapw_kxkxk = filterLaplacian() k = lapw_kxkxk.shape[0] self.pad = nn.ReplicationPad3d(2) self.lapw = torch.from_numpy(lapw_kxkxk).reshape(1, 1, k, k, k)
def lct(meas_hxwxt, wall_size, crop, bin_len): c = 3e8 width = wall_size / 2.0; bin_resolution = bin_len / c assert 2 ** int(np.log2(crop)) == crop snr = 1e-1 ########################################### meas_hxwxt = meas_hxwxt[:, :, :crop] # HxWxT sptial_grid = meas_hxwxt.shape[0] # H, N temprol_grid = meas_hxwxt.shape[2] # T, M trange = temprol_grid * c * bin_resolution ######################################################### # 0-1 gridz_M = np.arange(temprol_grid, dtype=np.float32) gridz_M = gridz_M / (temprol_grid - 1) gridz_MxNxN = np.tile(gridz_M.reshape(-1, 1, 1), [1, sptial_grid, sptial_grid]) ################################################### slope = width / trange psf = definePsf(sptial_grid, temprol_grid, slope) fpsf = np.fft.fftn(psf) invpsf = np.conjugate(fpsf) / (1 / snr + np.real(fpsf) ** 2 + np.imag(fpsf) ** 2) # invpsf = np.conjugate(fpsf) mtx_MxM, mtxi_MxM = resamplingOperator(temprol_grid) ############################################################# # diffuse data_TxHxW = np.transpose(meas_hxwxt, [2, 0, 1]) data_TxHxW = data_TxHxW * (gridz_MxNxN ** 4) datapad_2Tx2Hx2W = np.zeros(shape=(2 * temprol_grid, 2 * sptial_grid, 2 * sptial_grid), dtype=np.float32) left = mtx_MxM right = data_TxHxW.reshape(temprol_grid, -1) tmp = np.matmul(left, right).reshape(temprol_grid, sptial_grid, sptial_grid) datapad_2Tx2Hx2W[:temprol_grid, :sptial_grid, :sptial_grid] = tmp datafre = np.fft.fftn(datapad_2Tx2Hx2W) volumn_2Mx2Nx2N = np.fft.ifftn(datafre * invpsf) volumn_2Mx2Nx2N = np.real(volumn_2Mx2Nx2N) volumn_ZxYxX = volumn_2Mx2Nx2N[:temprol_grid, :sptial_grid, :sptial_grid] left = mtxi_MxM right = volumn_ZxYxX.reshape(temprol_grid, -1) tmp = np.matmul(left, right).reshape(temprol_grid, sptial_grid, sptial_grid) volumn_ZxYxX = tmp ################################ volumn_ZxYxX[volumn_ZxYxX < 0] = 0 dim = volumn_ZxYxX.shape[0] * 100 // 128 volumn_ZxYxX = volumn_ZxYxX[:dim] volumn_ZxYxX = volumn_ZxYxX / np.max(volumn_ZxYxX) front_view_HxW = np.max(volumn_ZxYxX, axis=0) cv2.imshow("re3", front_view_HxW / np.max(front_view_HxW)) # cv2.imshow('gt', imgt) cv2.waitKey() for frame in volumn_ZxYxX: cv2.imshow("re1", frame) cv2.imshow("re2", frame / np.max(frame)) cv2.waitKey(0)
def phasor(meas_hxwxt, wall_size, crop, bin_len): c = 3e8 width = wall_size / 2.0 bin_resolution = bin_len / c assert 2**int(np.log2(crop)) == crop ########################################### meas_hxwxt = meas_hxwxt[:, :, :crop] # HxWxT sptial_grid = meas_hxwxt.shape[0] # H, N temprol_grid = meas_hxwxt.shape[2] # T, M trange = temprol_grid * c * bin_resolution ################################################### slope = width / trange psf = definePsf(sptial_grid, temprol_grid, slope) fpsf = np.fft.fftn(psf) # invpsf = np.conjugate(fpsf) / (1 / snr + np.real(fpsf) ** 2 + np.imag(fpsf) ** 2) invpsf = np.conjugate(fpsf) mtx_MxM, mtxi_MxM = resamplingOperator(temprol_grid) ############################################################# # Step 0: define virtual wavelet properties s_lamda_limit = wall_size / (sptial_grid - 1) # sample spacing on the wall sampling_coeff = 2 # scale the size of the virtual wavelength (usually 2, optionally 3 for noisy scenes) virtual_wavelength = sampling_coeff * (s_lamda_limit * 2) # virtual wavelength in units of cm cycles = 5 # number of wave cycles in the wavelet, typically 4-6 ########################################################### data_TxHxW = np.transpose(meas_hxwxt, [2, 0, 1]) ############################################################ # Step 1: convolve measurement volume with virtual wave phasor_data_cos, phasor_data_sin = waveconv(bin_resolution, virtual_wavelength, cycles, data_TxHxW) # phasor_data_cos = single(phasor_data_cos); # phasor_data_sin = single(phasor_data_sin); ############################################################# # Step 2: transform virtual wavefield into LCT domain M = temprol_grid N = sptial_grid phasor_tdata_cos = np.zeros((2 * M, 2 * N, 2 * N), dtype=np.float32) phasor_tdata_sin = np.zeros((2 * M, 2 * N, 2 * N), dtype=np.float32) left = mtx_MxM right = phasor_data_cos.reshape(temprol_grid, -1) tmp = np.matmul(left, right).reshape(temprol_grid, sptial_grid, sptial_grid) phasor_tdata_cos[:temprol_grid, :sptial_grid, :sptial_grid] = tmp right = phasor_data_sin.reshape(temprol_grid, -1) tmp = np.matmul(left, right).reshape(temprol_grid, sptial_grid, sptial_grid) phasor_tdata_sin[:temprol_grid, :sptial_grid, :sptial_grid] = tmp ################################################################### # Step 3: convolve with backprojection kernel ''' tvol_phasorbp_sin = ifftn(fftn(phasor_tdata_sin).*bp_psf); tvol_phasorbp_sin = tvol_phasorbp_sin(1:end./2,1:end./2,1:end./2); phasor_tdata_cos = ifftn(fftn(phasor_tdata_cos).*bp_psf); phasor_tdata_cos = phasor_tdata_cos(1:end./2,1:end./2,1:end./2); ''' datafre = np.fft.fftn(phasor_tdata_sin) tvol_phasorbp_sin = np.fft.ifftn(datafre * invpsf) tvol_phasorbp_sin = tvol_phasorbp_sin[:M, :N, :N] datafre = np.fft.fftn(phasor_tdata_cos) tvol_phasorbp_cos = np.fft.ifftn(datafre * invpsf) tvol_phasorbp_cos = tvol_phasorbp_cos[:M, :N, :N] ############################################################### # Step 4: compute phasor field magnitude and inverse LCT ''' tvol = sqrt(tvol_phasorbp_sin.^2 + phasor_tdata_cos.^2); vol = reshape(mtxi*tvol(:,:),[M N N]); vol = max(real(vol),0); ''' tvol = np.sqrt(tvol_phasorbp_cos**2 + tvol_phasorbp_sin**2) left = mtxi_MxM right = tvol.reshape(temprol_grid, -1) tmp = np.matmul(left, right).reshape(temprol_grid, sptial_grid, sptial_grid) volumn_ZxYxX = np.real(tmp) volumn_ZxYxX[volumn_ZxYxX < 0] = 0 # volumn_ZxYxX[-10:] = 0 #######################################################33 volumn_ZxYxX = volumn_ZxYxX / np.max(volumn_ZxYxX) front_view_HxW = np.max(volumn_ZxYxX, axis=0) cv2.imshow("re3", front_view_HxW / np.max(front_view_HxW)) # cv2.imshow('gt', imgt) cv2.waitKey() for frame in volumn_ZxYxX: cv2.imshow("re1", frame) cv2.imshow("re2", frame / np.max(frame)) cv2.waitKey(0)