2017-11-12 2 views
0
나는 예에 따라 서로 다른 크기의 티파니 스택을 만드는 오전

을 개별 tiffs에서 티파니 스택을 만들기 여기에서 찾을 : http://www.bioimgtutorials.com/2016/08/03/creating-a-z-stack-in-python/파이썬

TIF 파일의 샘플은 여기에서 다운로드 할 수 있습니다 nucleus

나는 내부에 5 개의 tiff 파일로 된 폴더를 가지고있다. 가 같이 있도록 내가 ImageJ에에서 열 수 있도록 그들을 스택하려면 :

enter image description here

그리고 이것은 다음 코드로 작동합니다

from skimage import io 
import numpy as np 
import os 

dir = 'C:/Users/Mich/Desktop/tiff stack/' 

listfiles =[] 


for img_files in os.listdir(dir): 
    if img_files.endswith(".tif") : 
     listfiles.append(img_files) 



first_image = io.imread(dir+listfiles[0]) 

io.imshow(first_image) 

first_image.shape 

stack = np.zeros((5,first_image.shape[0],first_image.shape[1]),np.uint8) 



for n in range(0,5): 
    stack[n,:,:]= io.imread(dir+listfiles[n]) 

path_results = 'C:/Users/Mich/Desktop/' 
io.imsave(path_results+'Stack.tif' ,stack) 

이 문제는 때 온다 처음 4 개 또는 3 개를 쌓고 싶을뿐입니다. 4 TIFF 이미지와

예 :

stack=np.zeros((4,first_image.shape[0],first_image.shape[1]),np.uint8) 

    for n in range(0,4): 
     stack[n,:,:]= io.imread(dir+listfiles[n]) 

가 그럼 난 이런 종류의 결과 얻을 : enter image description here

및 폴더의 3 개 첫번째 이미지를 스택하는 동안, 그들은 함께 얻을!

stack=np.zeros((3,first_image.shape[0],first_image.shape[1]),np.uint8) 

    for n in range(0,3): 
     stack[n,:,:]= io.imread(dir+listfiles[n]) 

enter image description here

어디 그냥 크기 3, 4, 5의 다차원 스택의 개별 티파니를 추가 dosent 있도록 코드에서 내가 잘못?

답변

1

이미지 데이터의 색 공간 (photometric='minisblack')을 지정하십시오. 그렇지 않으면 tifffile 플러그인이 입력 배열의 모양을 추측합니다.

이것은 tifffile를 사용하여 짧은 버전은 직접 플러그인입니다 :

import glob 
from skimage.external import tifffile 

with tifffile.TiffWriter('Stack.tif') as stack: 
    for filename in glob.glob('nucleus/*.tif'): 
     stack.save(tifffile.imread(filename), photometric='minisblack') 
+0

우수함! 고마워. – michltm