How to use the mahotas.demos.load function in mahotas

To help you get started, we’ve selected a few mahotas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github luispedro / mahotas / mahotas / demos / surf_luispedro.py View on Github external
from __future__ import print_function
import numpy as np
import mahotas as mh
from mahotas.features import surf
from matplotlib import pyplot as plt

f = mh.demos.load('luispedro', as_grey=True)
f = f.astype(np.uint8)
spoints = surf.surf(f, 4, 6, 2)
print("Nr points:", len(spoints))

try:
    from sklearn.cluster import KMeans
    descrs = spoints[:,5:]
    k = 5
    values = KMeans(n_clusters=k).fit(descrs).labels_
    colors = np.array([(255-52*i,25+52*i,37**i % 101) for i in range(k)])
except:
    values = np.zeros(100, int)
    colors = np.array([(255,0,0)])

f2 = surf.show_surf(f, spoints[:100], values, colors)
fig,ax = plt.subplots()
github luispedro / BuildingMachineLearningSystemsWithPython / ch10 / lena-ring.py View on Github external
# This code is supporting material for the book
# Building Machine Learning Systems with Python
# by Willi Richert and Luis Pedro Coelho
# published by PACKT Publishing
#
# It is made available under the MIT License

import mahotas as mh
import numpy as np

# Read in the image
im = mh.demos.load('lena')

# This breaks up the image into RGB channels
r, g, b = im.transpose(2, 0, 1)
h, w = r.shape

# smooth the image per channel:
r12 = mh.gaussian_filter(r, 12.)
g12 = mh.gaussian_filter(g, 12.)
b12 = mh.gaussian_filter(b, 12.)

# build back the RGB image
im12 = mh.as_rgb(r12, g12, b12)

X, Y = np.mgrid[:h, :w]
X = X - h / 2.
Y = Y - w / 2.
github luispedro / BuildingMachineLearningSystemsWithPython / ch10 / figure13.py View on Github external
# This code is supporting material for the book
# Building Machine Learning Systems with Python
# by Willi Richert and Luis Pedro Coelho
# published by PACKT Publishing
#
# It is made available under the MIT License

import mahotas as mh
from mahotas.colors import rgb2grey
import numpy as np

# Adds a little salt-n-pepper noise to an image

im = mh.demos.load('lena')
im = rgb2grey(im)

# Salt & pepper arrays
salt = np.random.random(im.shape) > .975
pepper = np.random.random(im.shape) > .975

# salt is 170 & pepper is 30
# Some playing around showed that setting these to more extreme values looks
# very artificial. These look nicer

im = np.maximum(salt * 170, mh.stretch(im))
im = np.minimum(pepper * 30 + im * (~pepper), im)

mh.imsave('../1400OS_10_13+.jpg', im.astype(np.uint8))
github luispedro / mahotas / mahotas / demos / morphology.py View on Github external
from __future__ import print_function
import mahotas as mh
from pylab import gray, imshow, show


luispedro = mh.demos.load('luispedro')
luispedro = luispedro.max(2)
T = mh.otsu(luispedro)
lpbin = (luispedro > T)
eye = lpbin[112:180,100:190]
gray()
imshow(eye)
show()
imshow(~mh.morph.close(~eye))
show()
imshow(~mh.morph.open(~eye))
show()
github luispedro / mahotas / mahotas / demos / nuclear_distance_watershed.py View on Github external
import mahotas as mh
from os import path
import numpy as np
from matplotlib import pyplot as plt

nuclear = mh.demos.load('nuclear')
nuclear = nuclear[:,:,0]
nuclear = mh.gaussian_filter(nuclear, 1.)
threshed  = (nuclear > nuclear.mean())
distances = mh.stretch(mh.distance(threshed))
Bc = np.ones((9,9))

maxima = mh.morph.regmax(distances, Bc=Bc)
spots,n_spots = mh.label(maxima, Bc=Bc)
surface = (distances.max() - distances)
areas = mh.cwatershed(surface, spots)
areas *= threshed



import random
from matplotlib import colors
github luispedro / mahotas / mahotas / demos / wally.py View on Github external
from pylab import imshow
import mahotas as mh
import numpy as np

wally = mh.demos.load('DepartmentStore')
wfloat = wally.astype(float)
r,g,b = wfloat.transpose((2,0,1))
w = wfloat.mean(2)
pattern = np.ones((24,16), float)
for i in range(2):
    pattern[i::4] = -1
v = mh.convolve(r-w, pattern)
mask = (v == v.max())
mask = mh.dilate(mask, np.ones((48,24)))
wally -= np.array(.8*wally * ~mask[:,:,None], dtype=wally.dtype)
imshow(wally)