Пример #1
0
def iagsurf(f, vx=1, vy=0, vz=1):

    import numpy as np
    import ia636
    zd = ia636.iapad(f).astype(float)
    gv = zd[1:-1, 2:] - zd[1:-1, 1:-1]
    gv /= gv.max()
    #adshow(ia636.ianormalize(gv))
    gh = zd[2:, 1:-1] - zd[1:-1, 1:-1]
    gh /= gh.max()
    #adshow(ia636.ianormalize(gh))
    gz = 1.0 / (gv**2 + gh**2 + 1)
    #adshow(ia636.ianormalize(gz))
    gv *= gz
    gh *= gz
    #adshow(ia636.ianormalize(gv))
    #adshow(ia636.ianormalize(gh))
    v = np.sqrt(vx * vx + vy * vy + vz * vz)
    vx = vx / v
    vy = vy / v
    vz = vz / v
    gv *= vx
    gh *= vy
    gz *= vz
    gz += gh + gv
    return ia636.ianormalize(gz)
Пример #2
0
def preProcessing(imGrayLevel):
    
    #Escopo de algumas Operações básicas utilizadas no pré-processamento:
    #..............................................
    h = ia.iahistogram(imGrayLevel) #Equalização...
    n = imGrayLevel.size
    T = 255./n * np.cumsum(h)
    T = T.astype(uint8)
    #..............................................
    T1 = np.arange(256)  # função identidade
    T2 = ia.ianormalize(np.log(T1+30)) # logaritmica - realce partes escuras
    
    
    #T5 = ia.ianormalize(T1/50) # reduz o número de níveis de cinza
    #..................................................
    
    ax1.imshow(imRGB)
    ax1.set_title('rgb')
    
    ax2.imshow(imGrayLevel, vmin=0, vmax=255, cmap=plt.cm.gray)
    ax2.set_title('gray level')
    
    imGrayLevel =  denoise_tv_chambolle(imGrayLevel, weight=0.1, multichannel=True)
    imGrayLevel = img_as_ubyte(imGrayLevel)#Conversão de Float para UINT-8
    ax3.imshow(imGrayLevel, vmin=0, vmax=255, cmap=plt.cm.gray) #Filtro de suavização de textura
    ax3.set_title('tv signal filter')
    
    realceNucleos = T2[T[imGrayLevel]] #Realce de partes escuras da imagem equalizada
    ax4.imshow(realceNucleos, vmin=0, vmax=255, cmap=plt.cm.gray) 
    ax4.set_title('logaritimica')
    return realceNucleos
Пример #3
0
def hist_calc(wm, gm, bins, slice, hist_mat, subject, image):

    if image == 'yes':

        hist_wm = cv2.calcHist([ia.ianormalize(wm.astype('float32'))], [0],
                               None, [bins], [0, 256])
        hist_gm = cv2.calcHist([ia.ianormalize(gm.astype('float32'))], [0],
                               None, [bins], [0, 256])

        tags = ['wm_slice_' + str(slice), 'gm_slice_' + str(slice)]

        hist_mat_0 = np.hstack((tags[0], hist_wm[1:, 0]))
        hist_mat_1 = np.hstack((tags[1], hist_gm[1:, 0]))

        fig = plt.figure()
        line1, = plt.plot(hist_mat_0[1:].astype('float'),
                          color='blue',
                          label='WM Histogram')
        line2, = plt.plot(hist_mat_1[1:].astype('float'),
                          color='red',
                          label='GM Histogram')
        plt.grid(True, color="#a6a6a6", linestyle='dotted')
        plt.legend(handler_map={line1: HandlerLine2D(numpoints=3)})
        plt.title('slice ' + str(slice))

        name = '\\hist_slice_' + str(slice)

        his.save_dir(subject, name, hist_mat_0, fig='yes')

        hist_mat = np.vstack((hist_mat_0, hist_mat))
        hist_mat = np.vstack((hist_mat_1, hist_mat))
    else:

        hist_wm = cv2.calcHist([ia.ianormalize(wm.astype('float32'))], [0],
                               None, [bins], [0, 256])
        hist_gm = cv2.calcHist([ia.ianormalize(gm.astype('float32'))], [0],
                               None, [bins], [0, 256])

        tags = ['wm_slice_' + str(slice), 'gm_slice_' + str(slice)]

        hist_mat_0 = np.hstack((tags[0], hist_wm[1:, 0]))
        hist_mat_1 = np.hstack((tags[1], hist_gm[1:, 0]))

        hist_mat = np.vstack((hist_mat_0, hist_mat))
        hist_mat = np.vstack((hist_mat_1, hist_mat))

    return hist_mat
Пример #4
0
def iacolormap(type='gray'):

    if type == 'gray':
        ct = np.transpose(np.resize(np.arange(256), (3,256)))
    elif type == 'hsv':
        h = np.arange(256)/255.
        s = np.ones(256)
        v = np.ones(256)
        ct = ia.ianormalize(np.reshape(map(colorsys.hsv_to_rgb, h, s, v), (256,3)), [0,255]).astype(np.uint8)
    elif type == 'hot':
        n = np.floor(256./3) #np.floor(3./8*256)
        r = np.concatenate((np.arange(1,n+1)/n, np.ones(256-n)), 1)[:,np.newaxis]
        g = np.concatenate((np.zeros(n), np.arange(1,n+1)/n, np.ones(256-2*n)), 1)[:,np.newaxis]
        b = np.concatenate((np.zeros(2*n), np.arange(1,256-2*n+1)/(256-2*n)), 1)[:,np.newaxis]
        ct = ia.ianormalize(np.concatenate((r,g,b), 1), [0,255]).astype(np.uint8)
    elif type == 'cool':
        r = (np.arange(256)/255.)[:,np.newaxis]
        ct = ia.ianormalize(np.concatenate((r, 1-r, np.ones((256,1))), 1), [0,255]).astype(np.uint8)
    elif type == 'bone':
        ct = ia.ianormalize((7 * iacolormap('gray') + iacolormap('hot')[:,::-1]) / 8., [0,255]).astype(np.uint8)
    elif type == 'copper':
        cg = iacolormap('gray')/255.
        fac = np.dot(cg, [[1.25,0,0],[0,0.7812,0],[0,0,0.4975]])
        aux = np.minimum(1, fac)
        ct = ia.ianormalize(aux).astype(np.uint8)
    elif type == 'pink':
        ct = ia.ianormalize(np.sqrt((2*iacolormap('gray') + iacolormap('hot')) / 3), [0,255]).astype(np.uint8)
    else:
        ct = np.zeros((256,3))
    return ct
Пример #5
0
def iadither(f, n):
    import ia636

    H,W = f.shape
    D = 1.*array([[0,2],[3,1]])
    d = 1*D
    k = int(log(n/2.)/log(2.))
    for i in range(k):
        u = ones(D.shape)
        d1 = 4*D + d[0,0]*u
        d2 = 4*D + d[0,1]*u
        d3 = 4*D + d[1,0]*u
        d4 = 4*D + d[1,1]*u
        D = concatenate((concatenate((d1,d2),1), concatenate((d3,d4),1)))
    D = (255*abs(D/D.max())).astype('uint8')
    g = tile(D, array(f.shape)//array(D.shape) + array([1,1]))[:H,:W]
    g = ia636.ianormalize(f,[0,255]) >= g
    return g
Пример #6
0
def iadither(f, n):
    import ia636

    H, W = f.shape
    D = 1. * array([[0, 2], [3, 1]])
    d = 1 * D
    k = int(log(n / 2.) / log(2.))
    for i in range(k):
        u = ones(D.shape)
        d1 = 4 * D + d[0, 0] * u
        d2 = 4 * D + d[0, 1] * u
        d3 = 4 * D + d[1, 0] * u
        d4 = 4 * D + d[1, 1] * u
        D = concatenate((concatenate((d1, d2), 1), concatenate((d3, d4), 1)))
    D = (255 * abs(D / D.max())).astype('uint8')
    g = tile(D, array(f.shape) // array(D.shape) + array([1, 1]))[:H, :W]
    g = ia636.ianormalize(f, [0, 255]) >= g
    return g
Пример #7
0
def iagsurf(f, vx=1, vy=0, vz=1):

    import numpy as np
    import ia636
    zd = ia636.iapad(f).astype(float)
    gv = zd[1:-1,2:] - zd[1:-1,1:-1]
    gv /= gv.max()
    #adshow(ia636.ianormalize(gv))
    gh = zd[2:,1:-1] - zd[1:-1,1:-1]
    gh /= gh.max()
    #adshow(ia636.ianormalize(gh))
    gz = 1.0/(gv**2 + gh**2 + 1)
    #adshow(ia636.ianormalize(gz))
    gv *= gz
    gh *= gz
    #adshow(ia636.ianormalize(gv))
    #adshow(ia636.ianormalize(gh))
    v = np.sqrt(vx*vx + vy*vy + vz*vz)
    vx = vx/v; vy = vy/v; vz = vz/v;
    gv *= vx
    gh *= vy
    gz *= vz
    gz += gh + gv
    return ia636.ianormalize(gz)
Пример #8
0
def iacolormap(type='gray'):

    if type == 'gray':
        ct = np.transpose(np.resize(np.arange(256), (3, 256)))
    elif type == 'hsv':
        h = np.arange(256) / 255.
        s = np.ones(256)
        v = np.ones(256)
        ct = ia.ianormalize(
            np.reshape(map(colorsys.hsv_to_rgb, h, s, v), (256, 3)),
            [0, 255]).astype(np.uint8)
    elif type == 'hot':
        n = np.floor(256. / 3)  #np.floor(3./8*256)
        r = np.concatenate((np.arange(1, n + 1) / n, np.ones(256 - n)),
                           1)[:, np.newaxis]
        g = np.concatenate(
            (np.zeros(n), np.arange(1, n + 1) / n, np.ones(256 - 2 * n)),
            1)[:, np.newaxis]
        b = np.concatenate(
            (np.zeros(2 * n), np.arange(1, 256 - 2 * n + 1) / (256 - 2 * n)),
            1)[:, np.newaxis]
        ct = ia.ianormalize(np.concatenate((r, g, b), 1),
                            [0, 255]).astype(np.uint8)
    elif type == 'cool':
        r = (np.arange(256) / 255.)[:, np.newaxis]
        ct = ia.ianormalize(np.concatenate((r, 1 - r, np.ones((256, 1))), 1),
                            [0, 255]).astype(np.uint8)
    elif type == 'bone':
        ct = ia.ianormalize(
            (7 * iacolormap('gray') + iacolormap('hot')[:, ::-1]) / 8.,
            [0, 255]).astype(np.uint8)
    elif type == 'copper':
        cg = iacolormap('gray') / 255.
        fac = np.dot(cg, [[1.25, 0, 0], [0, 0.7812, 0], [0, 0, 0.4975]])
        aux = np.minimum(1, fac)
        ct = ia.ianormalize(aux).astype(np.uint8)
    elif type == 'pink':
        ct = ia.ianormalize(
            np.sqrt((2 * iacolormap('gray') + iacolormap('hot')) / 3),
            [0, 255]).astype(np.uint8)
    else:
        ct = np.zeros((256, 3))
    return ct
Пример #9
0
def iadftview(F):
    from ia636 import iafftshift
    from ia636 import ianormalize

    FM = iafftshift(log(abs(F) + 1))
    return ianormalize(FM).astype(uint8)
Пример #10
0
imGrayLevel = array(Image.open('img/teste/prob2.jpg').convert('L'))# Imagem em nível de cinza

#.................................................FIGURA 1
fig, ax = plt.subplots(2, 4, figsize=(14, 8))
fig.suptitle('George O. Barros - some operations')
ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8 = ax.ravel()

#Operações:
#..............................................
h = ia.iahistogram(imGrayLevel) #Equalização...
n = imGrayLevel.size
T = 255./n * np.cumsum(h)
T = T.astype(uint8)
#..............................................
T1 = np.arange(256)  # função identidade
T2 = ia.ianormalize(np.log(T1+1)) # logaritmica - realce partes escuras
T3 = 255 - T1 # negativo
T4 = 255 * (T1 > 128) # threshold 128
T5 = ia.ianormalize(T1/50) # reduz o número de níveis de cinza

g = np.copy(imRGB) #Quadriculado sobreposto
g[::10,:]=255
g[:,::10]=255

#PLOTS:
ax1.imshow(imRGB)
ax1.set_title('RGB')

ax2.imshow(imGrayLevel, vmin=0, vmax=255, cmap=plt.cm.gray)
ax2.set_title('Gray Level (0-255)')
from pylab import uint8
from skimage.filter import threshold_otsu
from skimage import img_as_ubyte #Conversão
from PIL import Image
from skimage.morphology import disk
from skimage.color import rgb2hed
from skimage.measure import label, regionprops 

print __doc__

glom_rgb = Image.open('s3.jpg')
glom_gl = glom_rgb.convert('L') #Gray Level

glom_hed = rgb2hed(glom_rgb) #hed
glom_h =  glom_hed[:, :, 0] #hematoxylim
glom_h = ia.ianormalize(glom_h)
selem = disk(10) #elemento estruturante
glom_h = np.array(glom_h) 
glom_h = 255 - uint8(glom_h)

#Segmentation
glom_by_reconsTopHat = morph.closerecth(glom_h,selem) #reconstrução morfológicas de fechamento

global_thresh = threshold_otsu(glom_by_reconsTopHat) #Otsu
glom_bin = glom_by_reconsTopHat > global_thresh + global_thresh*0.1 
glom_bin = img_as_ubyte(glom_bin)
selem = disk(3)    
glom_seg = morph.open(glom_bin, selem)
glom_seg = morph.close(glom_seg, selem) #Fechamento final

#Mostra as etapas
Пример #12
0
def iadftview(F):
    from ia636 import iafftshift
    from ia636 import ianormalize

    FM = iafftshift(log(abs(F)+1))
    return ianormalize(FM).astype(uint8)