Ejemplo n.º 1
0
def test_overlay():
    im = mh.demos.load('luispedro', as_grey=1)
    im = mh.stretch(im)
    assert np.all(mh.overlay(im).max(2) == im)
    edges = mh.sobel(im)

    im3 = mh.overlay(im, green=edges)
    assert np.all(im3[:,:,0] == im)
    assert np.all(im3[:,:,2] == im)
    assert np.all(im3[:,:,1] >= im )
Ejemplo n.º 2
0
def test_overlay():
    im = mh.demos.load('luispedro', as_grey=1)
    im = mh.stretch(im)
    assert np.all(mh.overlay(im).max(2) == im)
    edges = mh.sobel(im)

    im3 = mh.overlay(im, green=edges)
    assert np.all(im3[:, :, 0] == im)
    assert np.all(im3[:, :, 2] == im)
    assert np.all(im3[:, :, 1] >= im)
def main():
    Image_orig = mh.imread("./cameraman.tif")
    if Image_orig.ndim == 3:
       Image_orig_grey = mh.colors.rgb2grey(Image_orig)
    else:
       Image_orig_grey = Image_orig
    edge, kernel = phase_stretch_transform(Image_orig_grey, LPF, S, W, Threshold_min,
                                           Threshold_max, FLAG)
    Overlay = mh.overlay(Image_orig_grey, Edge)
    Edge = Edge.astype(np.uint8)*255
    plt.imshow(Edge)
    plt.show()
Ejemplo n.º 4
0
def main():
    Image_orig = mh.imread("../data/cameraman.tif")
    if Image_orig.ndim == 3:
        Image_orig_grey = mh.colors.rgb2grey(Image_orig)
    else:
        Image_orig_grey = Image_orig

    # 调用前面的函数,对图像进行相位拉伸变换,
    edge, kernel = phase_stretch_transform(Image_orig_grey, LPF,
                                           Phase_strength, Warp_strength,
                                           Threshold_min, Threshold_max,
                                           Morph_flag)

    # 显示图像,
    Overlay = mh.overlay(Image_orig_grey, edge)
    edge = edge.astype(np.uint8) * 255
    plt.imshow(edge)
    plt.show()
Ejemplo n.º 5
0
dnat = dnaf > T
pylab.gray()
nuclei1 = dnat
pylab.imshow(dnat)
pylab.show()

#labelling thereshold image
labeled, nr_objects = mh.label(dnat)
print nr_objects  # output number of objects
pylab.imshow(labeled)
pylab.jet()  # makes image colourful
pylab.show()

dnaf = mh.gaussian_filter(dnaf, 8)
rmax = mh.regmax(dnaf)
pylab.imshow(mh.overlay(
    dna, rmax))  # print dna and rmax (with second channel in red)
pylab.show()  # seeds only show when image is zoomed in

dnaf = mh.gaussian_filter(dnaf,
                          16)  # apply different filter to yield better result
rmax = mh.regmax(dnaf)
pylab.imshow(mh.overlay(dna, rmax))
pylab.show()

seeds, nr_nuclei = mh.label(rmax)  # nuclei count
print nr_nuclei  # unlike the example, the result is 36 compared to 22

dist = mh.distance(dnat)
dist = dist.max() - dist
dist -= dist.min()
dist = dist / float(dist.ptp()) * 255
                                          fillvalue=''):
            ax.imshow(img, **kwargs)
            ax.set_title(label)

    # show the original image and detected edges
    print('        Original Image       Edge Detected using PST')
    imshow_pair((Image_orig, Edge), cmap='gray')

    # Save results
    default_directory, filename = filepath.split('./Test_Images/')
    filename, extension = filename.split('.')
    output_path = default_directory + './Test_Images/' + filename + '_edge.tif'  # Saving the edge map with the extension tiff
    mh.imsave(output_path, Edge)

else:
    Overlay = mh.overlay(Image_orig_grey, Edge)

    # Display results
    def imshow_pair(image_pair, titles=('', ''), figsize=(10, 6), **kwargs):
        fig, axes = plt.subplots(ncols=len(image_pair), figsize=figsize)
        for ax, img, label in zip_longest(axes.ravel(),
                                          image_pair,
                                          titles,
                                          fillvalue=''):
            ax.imshow(img, **kwargs)
            ax.set_title(label)

    # show the original image, detected edges and an overlay of the original image with detected edges
    print(
        '      Original Image            Edge Detected using PST              Overlay'
    )
Ejemplo n.º 7
0
import pylab  # Dio od matplotlib.
import mahotas as mh
import cv2

image = cv2.imread('pictures/sky.png',
                   0)  # Ucitavamo sliku u grayscale prikazu.

filtered = mh.gaussian_filter(
    image, 10)  # Koristimo gauss filter za izostravanje slike.
result = filtered.astype(
    'uint8'
)  # Funckija mh.gaussian_filter() postavlja vrijednost varijable u float64.
rmax = mh.regmax(result)  # Trazi maksimalne vrijednosti.

print rmax
pylab.imshow(mh.overlay(image, rmax))
pylab.show()

labeled, nr_objects = mh.label(rmax)
# mh.overlay() funckija postavlja img kao pozadinu a preko nje postavlja vrijednosti variable rmax u crvenom kanalu.

print('Broj pronadenih objekata je {}.'.format(nr_objects))
pylab.imshow(labeled)
# pylab.gray()
pylab.show()

dist = mh.distance(result)
dist = dist.max() - dist
dist -= dist.min()
dist = dist / float(dist.ptp()) * 255
dist = dist.astype(np.uint8)
Ejemplo n.º 8
0
pen = mh.imread('images/Penguins.jpg')

#pylab.imshow(pen)
#pylab.show()

# dnaf = mh.gaussian_filter(dna, 8)
#change type to int for otsu to work
# dnaf = dnaf.astype('uint8')
# T = mh.thresholding.otsu(dnaf)
# pylab.imshow(dnaf > T)
# pylab.show()

dnaf = mh.gaussian_filter(dna, 8)
rmax = mh.regmax(dnaf)

pylab.imshow(mh.overlay(dna, rmax))
pylab.show()

pylab.imshow(dnaf)
pylab.show()
# labeled, nr_objects = mh.label(dnaf > T)
# print "nr_objects: {}".format(nr_objects)
# pylab.imshow(labeled)
# pylab.jet()
# pylab.show()

# pylab.imshow(dna)
# pylab.show()

print dna.shape
print dna.dtype
Ejemplo n.º 9
0
# Luis Pedro Coelho Mahotas: Open source software for scriptable computer vision in Journal of Open Research Software, vol 1, 2013. [DOI]
# mahotas.citation()


#### MAIN ####

# Laden der Bilder
dna = mh.imread("dna.jpeg")
# dna = mh.imread("nicolic_1.tif")
nuc = mh.demos.nuclear_image()

# Gaussfiltern und Tresholding
dnaf = mh.gaussian_filter(dna, 16)
# mahotas.thresholding() braucht "uint8"
dnaf = dnaf.astype("uint8")
T = mh.thresholding.otsu(dnaf)

# Zählen der Objekte, Ausgabe in int und Plottbaren Array mit nummerierten Flecken
labeled, nr_objects = mh.label(dnaf > T)
print nr_objects, labeled.shape, labeled.max()

# Seeds finden
rmax=mh.regmax(dnaf)

# pylab.imshow(rmax)
pylab.imshow(mh.overlay(dna, rmax))
# pylab.imshow(labeled)
# pylab.imshow(dnaf > T)
# pylab.imshow(nuc)
pylab.jet()
pylab.show()
Ejemplo n.º 10
0
def measure(origimage, cuts, gaussintensity, iteration):
    image = cut(origimage, cuts)
    adjustsize(origimage, image, cuts)
    if not default and iteration in modifyselection:
        limitmod = modifyselection[iteration]
    else:
        limitmod = 0
    ignore = findrim(image, limitmod)
    if rim and len(ignore) <= (cuts**2) * 0.33:
        while len(ignore) <= (cuts**2) * 0.33:
            limitmod += 3
            ignore = findrim(image, limitmod)
    elif len(ignore) >= (cuts**2) * 0.66:
        while len(ignore) >= (cuts**2) * 0.66:
            limitmod -= 3
            ignore = findrim(image, limitmod)
    avmod = len(ignore)
    threshold = applyth(image)
    if not default and iteration in increasegauss:
        usedgaussintensity = gaussintensity**increasegauss[iteration]
    else:
        usedgaussintensity = gaussintensity
    gauss = applygauss(image, usedgaussintensity)
    totalcellarea = 0.0
    subcount = int(math.sqrt(len(image)))
    for r in range(len(image)):
        printprogress(
            (iteration * len(image) + r + 1), (len(inputimages) * len(image)),
            prefix="processing " + str(len(inputimages) - len(badimages)) +
            " images",
            suffix="complete")
        if len(ignore) == 0 or r != ignore[0]:
            cellarea = 0.0
            area = image[r].shape[0] * image[r].shape[1]

            gaussth = gauss[r] > threshold[r]

            for array in gaussth:
                for pixel in array:
                    # variabel machen wenn Zellen hell
                    if pixel == 0:
                        cellarea += 1

            cellperc = (cellarea / area)
            inputimages[iteration][3] = cellperc * 100

            rmin = mh.regmin(gaussth)
            rmin = rmin.astype(np.uint8)

            plt.subplot(subcount, subcount, r + 1)
            plt.axis('off')
            plt.imshow(mh.overlay(image[r], rmin))

            totalcellarea += cellperc
        else:
            plt.subplot(subcount, subcount, r + 1)
            plt.axis('off')
            ignore.pop(0)
    plt.text(
        -7, 7,
        str("ID: " + str(iteration) + ", day: " +
            str(inputimages[iteration][1]) + ", " + str(substancename) +
            " concentration: " + str(inputimages[iteration][2]) + " %"))
    plt.text(
        -7, 6.5,
        str(cellname) + " coverage: " +
        str(round((totalcellarea / ((len(image)) - avmod)) * 100, 2)) + " %")
    plt.axis('off')
    pp.savefig()
    plt.gcf().clear()
Ejemplo n.º 11
0
import matplotlib.pylab as pyl
import mahotas as mh

# Circles
# Read and show image
circles = misc.imread('circles.png')
pyl.imshow(circles)
pyl.show()

#Threshold
T = mh.otsu(circles)
circlesTh = (circles > T)
circlesF = mh.gaussian_filter(circles, 33)
circlesRegmax = mh.regmax(circlesF)
labels, near = mh.label(circlesRegmax)
pyl.imshow(mh.overlay(circles, circlesRegmax))
pyl.show()

#Count circles
km, circlesCnt = mh.label(circlesRegmax)
print circlesCnt

#Find center points
centerMass = mh.center_of_mass(circles, labels)[1:]
print centerMass

#Objects
objects = mh.imread('objects.png')
pyl.imshow(objects)
pyl.show()
def PST(I,
        LPF=0.21,
        Phase_strength=0.48,
        Warp_strength=12.14,
        Threshold_min=-1,
        Threshold_max=0.0019,
        Morph_flag=1):
    # I: image
    # Gaussian Low Pass Filter
    #	LPF = 0.21
    # PST parameters:
    # 	Phase_strength = 0.48
    #	Warp_strength = 12.14
    # Thresholding parameters (for post processing after the edge is computed)
    #	Threshold_min = -1
    #	Threshold_max = 0.0019
    # To compute analog edge, set Morph_flag = 0 and to compute digital edge, set Morph_flag = 1
    # 	Morph_flag = 1
    I_initial = I
    if (len(I.shape) == 3):
        I = I.mean(axis=2)

    L = 0.5
    x = np.linspace(-L, L, I.shape[0])
    y = np.linspace(-L, L, I.shape[1])
    [X1, Y1] = (np.meshgrid(x, y))
    X = X1.T
    Y = Y1.T
    [THETA, RHO] = cart2pol(X, Y)

    # Apply localization kernel to the original image to reduce noise
    Image_orig_f = ((np.fft.fft2(I)))
    expo = np.fft.fftshift(
        np.exp(-np.power((np.divide(RHO, math.sqrt((LPF**2) /
                                                   np.log(2)))), 2)))
    Image_orig_filtered = np.real(
        np.fft.ifft2((np.multiply(Image_orig_f, expo))))
    # Constructing the PST Kernel
    PST_Kernel_1 = np.multiply(
        np.dot(RHO, Warp_strength), np.arctan(np.dot(RHO, Warp_strength))
    ) - 0.5 * np.log(1 + np.power(np.dot(RHO, Warp_strength), 2))
    PST_Kernel = PST_Kernel_1 / np.max(PST_Kernel_1) * Phase_strength
    # Apply the PST Kernel
    temp = np.multiply(np.fft.fftshift(np.exp(-1j * PST_Kernel)),
                       np.fft.fft2(Image_orig_filtered))
    Image_orig_filtered_PST = np.fft.ifft2(temp)

    # Calculate phase of the transformed image
    PHI_features = np.angle(Image_orig_filtered_PST)

    if Morph_flag == 0:
        out = PHI_features
        return out
    else:
        #   find image sharp transitions by thresholding the phase
        features = np.zeros((PHI_features.shape[0], PHI_features.shape[1]))
        features[PHI_features > Threshold_max] = 1  # Bi-threshold decision
        features[
            PHI_features <
            Threshold_min] = 1  # as the output phase has both positive and negative values
        features[I < (
            np.amax(I) / 20
        )] = 0  # Removing edges in the very dark areas of the image (noise)

        # apply binary morphological operations to clean the transformed image
        out = features
        out = mh.thin(out, 1)
        out = mh.bwperim(out, 4)
        out = mh.thin(out, 1)
        out = mh.erode(out, np.ones((1, 1)))

        Overlay = mh.overlay(I, out)
        return (out, Overlay)
Ejemplo n.º 13
0
                   np.fft.fft2(Image_orig_filtered))
Image_orig_filtered_PST = np.fft.ifft2(temp)

# Calculate phase of the transformed image
PHI_features = np.angle(Image_orig_filtered_PST)

# find image sharp transitions by thresholding the phase
features = np.zeros((PHI_features.shape[0], PHI_features.shape[1]))
features[PHI_features > Threshold_max] = 1  # Bi-threshold decision
features[
    PHI_features <
    Threshold_min] = 1  # as the output phase has both positive and negative values
features[image < (
    np.amax(image) /
    20)] = 0  # Removing edges in the very dark areas of the image (noise)

# apply binary morphological operations to clean the transformed image
out = features
out = mh.thin(out, 1)
out = mh.bwperim(out, 4)
out = mh.thin(out, 1)
out = mh.erode(out, np.ones((1, 1)))

overlay = mh.overlay(image, out)

plt.title('Overlay of original image with PST detected edges:\n' + ', LPF = ' +
          str(LPF) + ', phase_str = ' + str(Phase_strength) + ', warp_str = ' +
          str(Warp_strength) + ',\n t_min = ' + str(Threshold_min) +
          ', t_max = ' + str(Threshold_max))
plt.imshow(overlay)
plt.show()
Ejemplo n.º 14
0
                                          fillvalue=''):
            ax.imshow(img, **kwargs)
            ax.set_title(label)

    # show the original image and detected edges
    print('        Original Image       Edge Detected using PST')
    imshow_pair((Image_orig, Edge), cmap='gray')

    # Save results
    default_directory, filename = filepath.split('./Test_Images/')
    filename, extension = filename.split('.')
    output_path = default_directory + './Test_Images/' + filename + '_edge.tif'  # Saving the edge map with the extension tiff
    mh.imsave(output_path, Edge)

else:
    Overlay = mh.overlay(Image_orig, Edge)

    # Display results
    def imshow_pair(image_pair, titles=('', ''), figsize=(10, 6), **kwargs):
        fig, axes = plt.subplots(ncols=len(image_pair), figsize=figsize)
        for ax, img, label in zip_longest(axes.ravel(),
                                          image_pair,
                                          titles,
                                          fillvalue=''):
            ax.imshow(img, **kwargs)
            ax.set_title(label)

    # show the original image, detected edges and an overlay of the original image with detected edges
    print(
        '      Original Image            Edge Detected using PST              Overlay'
    )
Ejemplo n.º 15
0
import numpy as np
import pylab # Dio od matplotlib.
import mahotas as mh
import cv2

image = cv2.imread('pictures/sky.png', 0) # Ucitavamo sliku u grayscale prikazu.

filtered = mh.gaussian_filter(image, 10) # Koristimo gauss filter za izostravanje slike.
result = filtered.astype('uint8') # Funckija mh.gaussian_filter() postavlja vrijednost varijable u float64.
rmax = mh.regmax(result) # Trazi maksimalne vrijednosti.

print rmax
pylab.imshow(mh.overlay(image, rmax))
pylab.show()

labeled, nr_objects = mh.label(rmax)
# mh.overlay() funckija postavlja img kao pozadinu a preko nje postavlja vrijednosti variable rmax u crvenom kanalu.

print ('Broj pronadenih objekata je {}.'.format(nr_objects))
pylab.imshow(labeled)
# pylab.gray()
pylab.show()

dist = mh.distance(result)
dist = dist.max() - dist
dist -= dist.min()
dist = dist/float(dist.ptp()) * 255
dist = dist.astype(np.uint8)
objects = mh.cwatershed(dist, labeled)
whole = mh.segmentation.gvoronoi(objects) # Voronoi segemtacija, svaki piksel poprima vrijednost najblizeg maksimuma.
pylab.imshow(objects)