Ejemplo n.º 1
0
def show(all_files,prefix="",saturate=False):
    for f in all_files:
        name = os.path.basename(f)[:-len('.nii.gz')]
        img = irtk.imread(f,dtype="float32")
        if saturate:
            img = img.saturate().rescale()
        png_name = "img/"+prefix+name+".png"
        print png_name
        irtk.imshow(img,filename=png_name)
Ejemplo n.º 2
0
 def show_offline_preprocessing( self, folder ):
     if not os.path.exists(folder):
         os.makedirs(folder)
     all_files = glob( "offline_preprocessing/*_img.nii.gz" )
     for f in all_files:
         print f
         name = os.path.basename(f)[:-len("_img.nii.gz")]
         img = irtk.imread(f,dtype='float32')
         seg = irtk.imread("offline_preprocessing/"+name+"_seg.nii.gz",dtype='uint8')
         irtk.imshow(img,seg,filename=folder+"/"+name+".png",opacity=0.4)
Ejemplo n.º 3
0
#!/usr/bin/python

import irtk
from glob import glob
import os
import sys
import numpy as np

if not os.path.exists("png"):
    os.makedirs("png")

if len(sys.argv) == 1:
    all_files = glob("predictions/*/iter4_*_hard.nii.gz")
else:
    all_files = glob("predictions/" + sys.argv[1] + "/iter4_*_hard.nii.gz")

for f in all_files:
    print f
    name = os.path.basename(f)[len("iter4_"):-len("_hard.nii.gz")]
    img = irtk.imread("denoised/" + name + ".nii.gz", dtype='int32')
    mask = irtk.imread(f).transform(target=img.get_header(),
                                    interpolation="nearest")
    irtk.imshow(img, mask, filename="png/" + name + ".png", opacity=0.4)
    # exit(0)

forest.grow( 100 )

# print "writing"
# forest.write("test_forest")
# print "done"
# print "reading"
# forest = integralForest(folder="test_forest")
# print "done"

img = cv2.imread( "378.png",0).astype("float32")
img = img[np.newaxis,...].copy()
res = forest.predict_hard(img)
res = np.squeeze(res)#.copy()
irtk.imshow(irtk.Image(img),seg=res,filename="overlay_seg.png")

res /= res.max()
res *= 255
cv2.imwrite("res_hard.png",res.astype('uint8'))

res = forest.predict_soft(img)
res = np.squeeze(res)
#res /= res.max()

res *= 255
irtk.imshow(irtk.Image(img),overlay=res.astype('uint8'),colors='jet',filename="overlay.png")


cv2.imwrite("res_proba.png",res.astype('uint8'))
Ejemplo n.º 5
0
    # exit(0)

forest.grow(100)

# print "writing"
# forest.write("test_forest")
# print "done"
# print "reading"
# forest = integralForest(folder="test_forest")
# print "done"

img = cv2.imread("378.png", 0).astype("float32")
img = img[np.newaxis, ...].copy()
res = forest.predict_hard(img)
res = np.squeeze(res)  #.copy()
irtk.imshow(irtk.Image(img), seg=res, filename="overlay_seg.png")

res /= res.max()
res *= 255
cv2.imwrite("res_hard.png", res.astype('uint8'))

res = forest.predict_soft(img)
res = np.squeeze(res)
#res /= res.max()

res *= 255
irtk.imshow(irtk.Image(img),
            overlay=res.astype('uint8'),
            colors='jet',
            filename="overlay.png")
Ejemplo n.º 6
0
#!/usr/bin/python

import irtk
from glob import glob
import os
import sys
import numpy as np

if not os.path.exists("png"):
    os.makedirs("png")

if len(sys.argv) == 1:
    all_files = glob( "predictions/*/iter4_*_hard.nii.gz" )
else:
    all_files = glob( "predictions/"+sys.argv[1]+"/iter4_*_hard.nii.gz" )

for f in all_files:
    print f
    name = os.path.basename(f)[len("iter4_"):-len("_hard.nii.gz")]
    img = irtk.imread("denoised/"+name+".nii.gz",dtype='int32')
    mask = irtk.imread(f).transform(target=img.get_header(),interpolation="nearest")
    irtk.imshow(img,mask,filename="png/"+name+".png",opacity=0.4)
Ejemplo n.º 7
0
#!/usr/bin/python

import irtk
import cv2

mask = irtk.imread("mask.nii", dtype='uint8')
irtk.imwrite("mask.png", mask)

img = irtk.Image(cv2.imread("lena.png", 0))

irtk.imshow(img,
            mask,
            filename="initialisation.png",
            colors={
                1: (255, 0, 0),
                2: (0, 255, 0)
            },
            opacity=1.0)

mask2 = irtk.imread("mask2.nii", dtype='uint8')
irtk.imwrite("mask2.png", mask2)
irtk.imshow(img,
            mask2,
            filename="initialisation2.png",
            colors={
                1: (255, 0, 0),
                2: (0, 255, 0)
            },
            opacity=1.0)
Ejemplo n.º 8
0
#!/usr/bin/python

import irtk
from lib.mean_filter import mean_filter

img = irtk.imread( "data/fetus_head.nii.gz", dtype='float32' )

irtk.imshow( img, filename="before.png" )

img = irtk.Image( mean_filter(img, 5, 5, 5 ),
                  header=img.get_header() )

irtk.imshow( img, filename="after.png" )

Ejemplo n.º 9
0
#!/usr/bin/python

import irtk
import cv2

mask = irtk.imread("mask.nii",dtype='uint8')
irtk.imwrite("mask.png",mask)

img = irtk.Image( cv2.imread("lena.png",0) )

irtk.imshow( img, mask,
             filename="initialisation.png",
             colors={1:(255,0,0),2:(0,255,0)},
             opacity=1.0 )

mask2 = irtk.imread("mask2.nii",dtype='uint8')
irtk.imwrite("mask2.png",mask2)
irtk.imshow( img, mask2,
             filename="initialisation2.png",
             colors={1:(255,0,0),2:(0,255,0)},
             opacity=1.0 )