stock_img /= np.max(stock_img) # %% # Add Noise to the Image # ---------------------- # Now that we have an example array, we will begin using the ASPIRE toolkit. # First we will make an ASPIRE Image instance out of our data. # This is a light wrapper over the numpy array. Many ASPIRE internals # are built around an ``Image`` class. # Construct the Image class by passing it an array of data. img = Image(stock_img) # Downsample (just to speeds things up) new_resolution = img.res // 4 img = img.downsample(new_resolution) # We will begin processing by adding some noise. # We would like to create uniform noise for a 2d image with prescibed variance, noise_var = np.var(img.asnumpy()) * 5 noise_filter = ScalarFilter(dim=2, value=noise_var) # Then create a NoiseAdder. noise = NoiseAdder(seed=123, noise_filter=noise_filter) # We can apply the NoiseAdder to our image data. img_with_noise = noise.forward(img) # We will plot the original and first noisy image, # because we only have one image in our Image stack right now.
# %% # Apply a Uniform Shift # --------------------- # Apply a single shift to each image. shifts = np.array([100, 30]) im.shift(shifts).show() # %% # Apply Image-wise Shifts # ----------------------- # Or apply shifts corresponding to to each image. shifts = np.array([[300 * i, 100 * i] for i in range(1, im.n_images + 1)]) im.shift(shifts).show() # %% # Downsampling # ------------ im.downsample(80).show() # %% # CTF Filter # ---------- # pixel_size/defous_u/defocus_v in Angstrom, voltage in kV filter = CTFFilter(pixel_size=1, voltage=100, defocus_u=1500, defocus_v=2000) im.filter(filter).show()