R-str_pad使用

R-str_pad

格式:str_pad(string,length,string_local,char)
length:填补之后的字符串长度 #length(string)查看之前长度
string_local:“left”/“rIght”/“both” #填补字符串的位置
char:“0”/" "/… #填补字符串长度
之前搜索到填补位置和填补字符参数位置相反,不能使用
大概r语言和其他语言str_pad使用参数搞混了

import numpy as np import numpy.fft as fft import scipy.ndimage as nd import imageio import scipy.misc as misc from math import pi #Read in source image #source = nd.imread("einstein.bmp", flatten=True) source = imageio.imread("einstein.bmp", as_gray=True) #Pad image to simulate oversampling pad_len = len(source) padded = np.pad(source, ((pad_len, pad_len),(pad_len, pad_len)), 'constant', constant_values=((0,0),(0,0))) ft = fft.fft2(padded) #simulate diffraction pattern diffract = np.abs(ft) l = len(padded) #keep track of where the image is vs the padding mask = np.ones((pad_len+2,pad_len+2)) mask = np.pad(mask, ((pad_len-1, pad_len-1),(pad_len-1, pad_len-1)), 'constant', constant_values=((0,0),(0,0))) #Initial guess using random phase info guess = diffract * np.exp(1j * np.random.rand(l,l) * 2 * pi) #number of iterations r = 801 #step size parameter beta = 0.8 #previous result prev = None for s in range(0,r): #apply fourier domain constraints update = diffract * np.exp(1j * np.angle(guess)) inv = fft.ifft2(update) inv = np.real(inv) if prev is None: prev = inv #apply real-space constraints temp = inv for i in range(0,l): for j in range(0,l): #image region must be positive if inv[i,j] < 0 and mask[i,j] == 1: inv[i,j] = prev[i,j] - beta*inv[i,j] #push support region intensity toward zero if mask[i,j] == 0: inv[i,j] = prev[i,j] - beta*inv[i,j] prev = temp guess = fft.fft2(inv) #save an image of the progress if s % 10 == 0: #imageio.imsave("/Users/chasegoddard/Stuff/CDI/code/save/progress" + str(s) + # ".bmp", prev) imageio.imsave("C:/Users/Administrator/Desktop/仿真结果/结果" + str(s) + ".bmp", prev) print(s)
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值