Sunday 15 August 2010

python - Stacking images as numpy array -



python - Stacking images as numpy array -

i'm trying utilize for-loop stack 6 different images 1 on top of create 3d stack.i'm new python...and not able figure out. how can create stack , how can access each image in stack later? code this...

image = data.camera() noisyimage = np.zeros(image.shape(0),image.shape(1)) fig = plt.figure(figsize=(12,4)) in range(6): noisyimage = util.random_noise(image,mode='gaussian',seed=i) result = np.dstack(noisyimage,noisyimage) ax = plt.subplot(2,3,i)

try this:

# reshape array (n,m) 1 (n,m,1) no increment in size happens. n1=np.reshape(noisyimage,noisyimage.shape+(1,)) if(i==1): result=n1 else: # concatenate n,m,1 version of array stack using 3rd index (last index) axis. result=np.concatenate(result,n1,axis=n1.ndim-1)

the code below more general implementation (from reply above taken) apply function designed applied single channel channels in image.

def matrixtomultichannel(f,x,*args,**kwargs): nchannels=x.shape[-1] y=np.reshape(x,(x.size/nchannels,nchannels)) in range(0,nchannels): yi=np.reshape(y[:,i],x.shape[:x.ndim-1]) m1=genericf(f,yi,*args, **kwargs) m1=np.reshape(m1,m1.shape+(1,)) if(i==0): fout=m1 else: fout=np.concatenate((fout,m1),axis=m1.ndim-1) homecoming fout

python arrays image numpy

No comments:

Post a Comment