def kmeans_centers_plot(clus_center_dir): kmeans_clus = AIF.pickle_load(op_join(clus_center_dir, 'kmeans.pickle')) ccents = AIF.pickle_load(op_join(clus_center_dir, 'ccents.pickle')) # export slices for visual inspection if False: for i in ccents: auto.dsp_cub(ccents[i]) else: clus_center_figure_dir = op_join(clus_center_dir, 'fig') if os.path.isdir(clus_center_figure_dir): shutil.rmtree(clus_center_figure_dir) os.makedirs(clus_center_figure_dir) # normalize across all images min_t = N.min([ccents[_].min() for _ in ccents]) max_t = N.max([ccents[_].max() for _ in ccents]) assert max_t > min_t ccents_t = {_: ((ccents[_] - min_t) / (max_t - min_t)) for _ in ccents} ccents_t = ccents for i in ccents_t: clus_siz = len(kmeans_clus[i]) t = AIVU.cub_img(ccents_t[i])['im'] AIIO.save_png(t, op_join(clus_center_figure_dir, '%003d--%d.png' % (i, clus_siz)), normalize=False)
def output_image(v, path): TIIO.save_png(TIVU.cub_img(v)['im'], path)
def output_image(v, path): """ Saves the sliced image of model v to path """ AIIO.save_png(AIVU.cub_img(v)['im'], path)
loc_proportion = 0.1 loc_max = N.array(v.shape, dtype=float) * loc_proportion angle = GAL.random_rotation_angle_zyz() loc_r = (N.random.random(3) - 0.5) * loc_max vr = GR.rotate(v, angle=angle, loc_r=loc_r, default_val=0.0) # generate simulated subtomogram vb from v vb = TSRSC.do_reconstruction(vr, op, verbose=True) print('vb', 'mean', vb.mean(), 'std', vb.std(), 'var', vb.var()) # save v and vb as 3D grey scale images TIF.put_mrc(vb, '/tmp/vb.mrc', overwrite=True) TIF.put_mrc(v, '/tmp/v.mrc', overwrite=True) # save images of the slices of the corresponding 3D iamges for visual inspection import aitom.image.io as IIO import aitom.tomominer.image.vol.util as TIVU IIO.save_png(TIVU.cub_img(vb)['im'], "/tmp/vb.png") IIO.save_png(TIVU.cub_img(v)['im'], "/tmp/v.png") if True: # verify the correctness of SNR estimation vb_rep = TSRSC.do_reconstruction(vr, op, verbose=True) import scipy.stats as SS # calculate SNR vb_corr = SS.pearsonr(vb.flatten(), vb_rep.flatten())[0] vb_snr = 2 * vb_corr / (1 - vb_corr) print('SNR', 'parameter', op['model']['SNR'], 'estimated', vb_snr) # fsc = ssnr / (2.0 + ssnr)
import aitom.geometry.ang_loc as TGAL import aitom.geometry.rotate as TGR import random import numpy as N # randomly rotate and translate v loc_proportion = 0.1 loc_max = N.array(v.shape, dtype=float) * loc_proportion angle = TGAL.random_rotation_angle_zyz() loc_r = (N.random.random(3) - 0.5) * loc_max vr = TGR.rotate(v, angle=angle, loc_r=loc_r, default_val=0.0) #-------------------------------- # align vr against v import aitom.align.util as TAU al = TAU.align_vols_no_mask(v, vr) print('rigid transform of alignment', al) vr_i = TGR.rotate( vr, angle=al['angle'], loc_r=al['loc'], default_val=0.0 ) # rotate vr according to the alignment, expected to produce an image similiar to v # save images of the slices of the corresponding 3D iamges for visual inspection import aitom.image.io as TIIO import aitom.image.vol.util as TIVU TIIO.save_png(TIVU.cub_img(v)['im'], "v.png") TIIO.save_png(TIVU.cub_img(vr)['im'], "vr.png") TIIO.save_png(TIVU.cub_img(vr_i)['im'], "vr_i.png")
a = IF.read_mrc_data("data/IS002_291013_005_subtomo000001.mrc") # denoising using gaussian filter for visualization from aitom.filter.gaussian import smooth a = smooth(a, sigma=8) # display image using image module import aitom.image.vol.util as IVU ''' a_im is a dict: 'im': image data, type of numpy.ndarray, elements in [0, 1] 'vt': volume data ''' a_im = IVU.cub_img(a) print(type(a_im['im'])) print(a_im['im'].shape) print(a_im['im'][1][1]) import matplotlib.pyplot as plt plt.imshow(a_im['im'], cmap='gray') # save the figure into a png file import aitom.image.io as IIO IIO.save_png(m=a_im['im'], name='/tmp/a_im.png') # display image using `image.util.dsp_cub` IVU.dsp_cub(a) # save slices of a into a png file IIO.save_cub_img(v=a, name='/tmp/a.png')
def map2png(map, file): import aitom.image.io as IIO import aitom.image.vol.util as TIVU IIO.save_png(TIVU.cub_img(map)['im'], file)
a_im = im_vol_util.cub_img(a) ''' a_im is a dict: 'im': image data 'vt': volume data image data is type of numpy.ndarray, elements $\in$ [0, 1] ''' print(type(a_im['im'])) print(a_im['im'].shape) print(a_im['im'][1][1]) import matplotlib.pyplot as plt #%matplotlib notebook plt.imshow(a_im['im'], cmap='gray') # save the figure into a png file import aitom.image.io as image_io image_io.save_png(m=a_im['im'], name='/tmp/a_im.png') # display image using `image.util.dsp_cub` im_vol_util.dsp_cub(a) # save slices of a into a png file image_io.save_cub_png(v=a, name='/tmp/a.png')
def visualize(img, path): t = AIVU.cub_img(img)['im'] AIIO.save_png(t, path)