mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-16 11:21:25 +08:00
Merge pull request #1543 from stefanv/docs/remove_logo
Remove logo (moved to branding repo)
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
.PHONY: logo
|
||||
|
||||
logo: green_orange_snake.png snake_logo.svg
|
||||
inkscape --export-png=scikit_image_logo.png --export-dpi=100 \
|
||||
--export-area-drawing --export-background-opacity=1 \
|
||||
snake_logo.svg
|
||||
python shrink_logo.py
|
||||
|
||||
green_orange_snake.png:
|
||||
python scikit_image_logo.py --no-plot
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 45 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 76 KiB |
@@ -1,165 +0,0 @@
|
||||
"""
|
||||
Script to draw skimage logo using Scipy logo as stencil. The easiest
|
||||
starting point is the `plot_colorized_logo`.
|
||||
|
||||
Original snake image from pixabay [1]_
|
||||
|
||||
.. [1] http://pixabay.com/en/snake-green-toxic-close-yellow-3237/
|
||||
"""
|
||||
import sys
|
||||
if len(sys.argv) != 2 or sys.argv[1] != '--no-plot':
|
||||
print("Run with '--no-plot' flag to generate logo silently.")
|
||||
else:
|
||||
import matplotlib as mpl
|
||||
mpl.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import numpy as np
|
||||
|
||||
import skimage.io as sio
|
||||
from skimage import img_as_float
|
||||
from skimage.color import gray2rgb, rgb2gray
|
||||
from skimage.exposure import rescale_intensity
|
||||
from skimage.filters import sobel
|
||||
|
||||
import scipy_logo
|
||||
|
||||
# Utility functions
|
||||
# =================
|
||||
|
||||
def colorize(image, color, whiten=False):
|
||||
"""Return colorized image from gray scale image.
|
||||
|
||||
The colorized image has values from ranging between black at the lowest
|
||||
intensity to `color` at the highest. If `whiten=True`, then the color
|
||||
ranges from `color` to white.
|
||||
"""
|
||||
color = np.asarray(color)[np.newaxis, np.newaxis, :]
|
||||
image = image[:, :, np.newaxis]
|
||||
if whiten:
|
||||
# truncate and stretch intensity range to enhance contrast
|
||||
image = rescale_intensity(image, in_range=(0.3, 1))
|
||||
return color * (1 - image) + image
|
||||
else:
|
||||
return image * color
|
||||
|
||||
|
||||
def prepare_axes(ax):
|
||||
plt.sca(ax)
|
||||
ax.xaxis.set_visible(False)
|
||||
ax.yaxis.set_visible(False)
|
||||
for spine in ax.spines.values():
|
||||
spine.set_visible(False)
|
||||
|
||||
|
||||
# Logo generating classes
|
||||
# =======================
|
||||
|
||||
class LogoBase(object):
|
||||
|
||||
def __init__(self):
|
||||
self.logo = scipy_logo.ScipyLogo(radius=self.radius)
|
||||
self.mask_1 = self.logo.get_mask(self.image.shape, 'upper left')
|
||||
self.mask_2 = self.logo.get_mask(self.image.shape, 'lower right')
|
||||
|
||||
edges = np.array([sobel(img) for img in self.image.T]).T
|
||||
# truncate and stretch intensity range to enhance contrast
|
||||
self.edges = rescale_intensity(edges, in_range=(0, 0.4))
|
||||
|
||||
def _crop_image(self, image):
|
||||
w = 2 * self.radius
|
||||
x, y = self.origin
|
||||
return image[y:y + w, x:x + w]
|
||||
|
||||
def plot_curve(self, **kwargs):
|
||||
self.logo.plot_snake_curve(**kwargs)
|
||||
|
||||
|
||||
class SnakeLogo(LogoBase):
|
||||
|
||||
radius = 250
|
||||
origin = (420, 0)
|
||||
|
||||
def __init__(self):
|
||||
image = sio.imread('data/snake_pixabay.jpg')
|
||||
image = self._crop_image(image)
|
||||
self.image = img_as_float(image)
|
||||
|
||||
LogoBase.__init__(self)
|
||||
|
||||
|
||||
snake_color = SnakeLogo()
|
||||
snake = SnakeLogo()
|
||||
# turn RGB image into gray image
|
||||
snake.image = rgb2gray(snake.image)
|
||||
snake.edges = rgb2gray(snake.edges)
|
||||
|
||||
|
||||
# Demo plotting functions
|
||||
# =======================
|
||||
|
||||
def plot_colorized_logo(logo, color, edges='light', whiten=False):
|
||||
"""Convenience function to plot artificially-colored logo.
|
||||
|
||||
The upper-left half of the logo is an edge filtered image, while the
|
||||
lower-right half is unfiltered.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
logo : LogoBase instance
|
||||
color : length-3 sequence of floats or 2 length-3 sequences
|
||||
RGB color spec. Float values should be between 0 and 1.
|
||||
edges : {'light'|'dark'}
|
||||
Specifies whether Sobel edges are drawn light or dark
|
||||
whiten : bool or 2 bools
|
||||
If True, a color value less than 1 increases the image intensity.
|
||||
"""
|
||||
if not hasattr(color[0], '__iter__'):
|
||||
color = [color] * 2 # use same color for upper-left & lower-right
|
||||
if not hasattr(whiten, '__iter__'):
|
||||
whiten = [whiten] * 2 # use same setting for upper-left & lower-right
|
||||
|
||||
image = gray2rgb(np.ones_like(logo.image))
|
||||
mask_img = gray2rgb(logo.mask_2)
|
||||
mask_edge = gray2rgb(logo.mask_1)
|
||||
|
||||
# Compose image with colorized image and edge-image.
|
||||
if edges == 'dark':
|
||||
logo_edge = colorize(1 - logo.edges, color[0], whiten=whiten[0])
|
||||
else:
|
||||
logo_edge = colorize(logo.edges, color[0], whiten=whiten[0])
|
||||
logo_img = colorize(logo.image, color[1], whiten=whiten[1])
|
||||
image[mask_img] = logo_img[mask_img]
|
||||
image[mask_edge] = logo_edge[mask_edge]
|
||||
|
||||
logo.plot_curve(lw=5, color='w') # plot snake curve on current axes
|
||||
plt.imshow(image)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Colors to use for the logo:
|
||||
red = (1, 0, 0)
|
||||
blue = (0.35, 0.55, 0.85)
|
||||
green_orange = ((0.6, 0.8, 0.3), (1, 0.5, 0.1))
|
||||
|
||||
def plot_all():
|
||||
color_list = [red, blue, green_orange]
|
||||
edge_list = ['light', 'dark']
|
||||
f, axes = plt.subplots(nrows=len(edge_list), ncols=len(color_list))
|
||||
for axes_row, edges in zip(axes, edge_list):
|
||||
for ax, color in zip(axes_row, color_list):
|
||||
prepare_axes(ax)
|
||||
plot_colorized_logo(snake, color, edges=edges)
|
||||
plt.tight_layout()
|
||||
|
||||
def plot_official_logo():
|
||||
f, ax = plt.subplots()
|
||||
prepare_axes(ax)
|
||||
plot_colorized_logo(snake, green_orange, edges='dark',
|
||||
whiten=(False, True))
|
||||
plt.savefig('green_orange_snake.png', bbox_inches='tight')
|
||||
|
||||
plot_all()
|
||||
plot_official_logo()
|
||||
|
||||
plt.show()
|
||||
@@ -1,248 +0,0 @@
|
||||
"""
|
||||
Code used to trace Scipy logo.
|
||||
"""
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from skimage import io
|
||||
from skimage import data
|
||||
|
||||
from skimage.measure import points_in_poly
|
||||
|
||||
class SymmetricAnchorPoint(object):
|
||||
"""Anchor point in a parametric curve with symmetric handles
|
||||
|
||||
Parameters
|
||||
----------
|
||||
pt : length-2 sequence
|
||||
(x, y) coordinates of anchor point
|
||||
theta : float
|
||||
angle of control handle
|
||||
length : float
|
||||
half-length of symmetric control handle. Each control point is `length`
|
||||
distance away from the anchor point.
|
||||
use_degrees : bool
|
||||
If True, convert input `theta` from degrees to radians.
|
||||
"""
|
||||
|
||||
def __init__(self, pt, theta, length, use_degrees=False):
|
||||
self.pt = pt
|
||||
if use_degrees:
|
||||
theta = theta * np.pi / 180
|
||||
self.theta = theta
|
||||
self.length = length
|
||||
|
||||
def control_points(self):
|
||||
"""Return control points for symmetric handles
|
||||
|
||||
The first point is in the direction of theta and the second is directly
|
||||
opposite. For example, if `theta = 0`, then the first `p1` will be
|
||||
directly to the right of the anchor point, and `p2` will be directly
|
||||
to the left.
|
||||
"""
|
||||
theta = self.theta
|
||||
offset = self.length * np.array([np.cos(theta), np.sin(theta)])
|
||||
p1 = self.pt + offset
|
||||
p2 = self.pt - offset
|
||||
return p1, p2
|
||||
|
||||
def __repr__(self):
|
||||
v = (self.pt, self.theta * 180/np.pi, self.length)
|
||||
return 'SymmetricAnchorPoint(pt={0}, theta={1}, length={2})'.format(*v)
|
||||
|
||||
|
||||
def curve_from_anchor_points(pts):
|
||||
"""Return curve from a list of SymmetricAnchorPoints"""
|
||||
assert len(pts) > 1
|
||||
bezier_pts = []
|
||||
for anchor in pts:
|
||||
c1, c2 = anchor.control_points()
|
||||
bezier_pts.extend([c2, anchor.pt, c1])
|
||||
# clip control points from ends
|
||||
bezier_pts = bezier_pts[1:-1]
|
||||
x, y = [], []
|
||||
# every third point is an anchor point
|
||||
for i in range(0, len(bezier_pts)-1, 3):
|
||||
xi, yi = cubic_curve(*bezier_pts[i:i+4])
|
||||
x.append(xi)
|
||||
y.append(yi)
|
||||
return np.hstack(x), np.hstack(y)
|
||||
|
||||
|
||||
def cubic_curve(p0, p1, p2, p3, npts=20):
|
||||
"""Return points on a cubic Bezier curve
|
||||
|
||||
Parameters
|
||||
----------
|
||||
p0, p3 : length-2 sequences
|
||||
end points of curve
|
||||
p1, p2 : length-2 sequences
|
||||
control points of curve
|
||||
npts : int
|
||||
number of points to return (including end points)
|
||||
|
||||
Returns
|
||||
-------
|
||||
x, y : arrays
|
||||
points on cubic curve
|
||||
"""
|
||||
t = np.linspace(0, 1, npts)[:, np.newaxis]
|
||||
# cubic bezier curve from http://en.wikipedia.org/wiki/Bezier_curve
|
||||
b = (1-t)**3 * p0 + 3*t*(1-t)**2 * p1 + 3*t**2*(1-t) * p2 + t**3 * p3
|
||||
x, y = b.transpose()
|
||||
return x, y
|
||||
|
||||
|
||||
class Circle(object):
|
||||
|
||||
def __init__(self, center, radius):
|
||||
self.center = center
|
||||
self.radius = radius
|
||||
|
||||
def point_from_angle(self, angle):
|
||||
r = self.radius
|
||||
# `angle` can be a scalar or 1D array: transpose twice for best results
|
||||
pts = r * np.array((np.cos(angle), np.sin(angle))).T + self.center
|
||||
return pts.T
|
||||
|
||||
def plot(self, **kwargs):
|
||||
ax = kwargs.pop('ax', plt.gca())
|
||||
fc = kwargs.pop('fc', 'none')
|
||||
c = plt.Circle(self.center, self.radius, fc=fc, **kwargs)
|
||||
ax.add_patch(c)
|
||||
|
||||
|
||||
class ScipyLogo(object):
|
||||
"""Object to generate scipy logo
|
||||
|
||||
Parameters
|
||||
----------
|
||||
center : length-2 array
|
||||
the Scipy logo will be centered on this point.
|
||||
radius : float
|
||||
radius of logo
|
||||
"""
|
||||
|
||||
CENTER = np.array((254, 246))
|
||||
RADIUS = 252.0
|
||||
THETA_START = 2.58
|
||||
THETA_END = -0.368
|
||||
|
||||
def __init__(self, center=None, radius=None):
|
||||
if center is None:
|
||||
if radius is None:
|
||||
center = self.CENTER
|
||||
else:
|
||||
center = np.array((radius, radius))
|
||||
self.center = center
|
||||
if radius is None:
|
||||
radius = self.RADIUS
|
||||
self.radius = radius
|
||||
|
||||
|
||||
# calculate end points of curve so that it lies exactly on circle
|
||||
logo_circle = Circle(self.CENTER, self.RADIUS)
|
||||
s_start = logo_circle.point_from_angle(self.THETA_START)
|
||||
s_end = logo_circle.point_from_angle(self.THETA_END)
|
||||
|
||||
self.circle = Circle(self.center, self.radius)
|
||||
# note that angles are clockwise because of inverted y-axis
|
||||
self._anchors = [SymmetricAnchorPoint(*t, use_degrees=True)
|
||||
for t in [(s_start, -37, 90),
|
||||
((144, 312), 7, 20),
|
||||
((205, 375), 52, 50),
|
||||
((330, 380), -53, 60),
|
||||
((290, 260),-168, 50),
|
||||
((217, 245),-168, 50),
|
||||
((182, 118), -50, 60),
|
||||
((317, 125), 53, 60),
|
||||
((385, 198), 10, 20),
|
||||
(s_end, -25, 60)]]
|
||||
# normalize anchors so they have unit radius and are centered at origin
|
||||
for a in self._anchors:
|
||||
a.pt = (a.pt - self.CENTER) / self.RADIUS
|
||||
a.length = a.length / self.RADIUS
|
||||
|
||||
def snake_anchors(self):
|
||||
"""Return list of SymmetricAnchorPoints defining snake curve"""
|
||||
anchors = []
|
||||
for a in self._anchors:
|
||||
pt = self.radius * a.pt + self.center
|
||||
length = self.radius * a.length
|
||||
anchors.append(SymmetricAnchorPoint(pt, a.theta, length))
|
||||
return anchors
|
||||
|
||||
def snake_curve(self):
|
||||
"""Return x, y coordinates of snake curve"""
|
||||
return curve_from_anchor_points(self.snake_anchors())
|
||||
|
||||
def plot_snake_curve(self, **kwargs):
|
||||
ax = kwargs.pop('ax', plt.gca())
|
||||
x, y = self.snake_curve()
|
||||
ax.plot(x, y, 'k', **kwargs)
|
||||
|
||||
def plot_circle(self, **kwargs):
|
||||
self.circle.plot(**kwargs)
|
||||
|
||||
def plot_image(self, **kwargs):
|
||||
ax = kwargs.pop('ax', plt.gca())
|
||||
img = io.imread('data/scipy.png')
|
||||
ax.imshow(img, **kwargs)
|
||||
|
||||
def get_mask(self, shape, region):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
region : {'upper left', 'lower right'}
|
||||
"""
|
||||
if region == 'upper left':
|
||||
theta = np.linspace(self.THETA_END, self.THETA_START - 2 * np.pi)
|
||||
elif region == 'lower right':
|
||||
theta = np.linspace(self.THETA_END, self.THETA_START)
|
||||
else:
|
||||
msg = "Expected 'upper left' or 'lower right'; got %s" % region
|
||||
raise ValueError(msg)
|
||||
xy_circle = self.circle.point_from_angle(theta).T
|
||||
x, y = self.snake_curve()
|
||||
xy_curve = np.array((x, y)).T
|
||||
xy_poly = np.vstack((xy_curve, xy_circle))
|
||||
|
||||
h, w = shape[:2]
|
||||
y_img, x_img = np.mgrid[:h, :w]
|
||||
xy_points = np.column_stack((x_img.flat, y_img.flat))
|
||||
|
||||
mask = points_in_poly(xy_points, xy_poly)
|
||||
return mask.reshape((h, w))
|
||||
|
||||
|
||||
def plot_scipy_trace():
|
||||
plt.figure()
|
||||
logo = ScipyLogo()
|
||||
logo.plot_snake_curve()
|
||||
logo.plot_circle()
|
||||
logo.plot_image()
|
||||
plot_anchors(logo.snake_anchors())
|
||||
|
||||
|
||||
def plot_anchors(anchors, color='r', alpha=0.7):
|
||||
for a in anchors:
|
||||
c = a.control_points()
|
||||
x, y = np.transpose(c)
|
||||
plt.plot(x, y, 'o-', color=color, mfc='w', mec=color, alpha=alpha)
|
||||
plt.plot(a.pt[0], a.pt[1], 'o', color=color, alpha=alpha)
|
||||
|
||||
|
||||
def plot_snake_overlay():
|
||||
plt.figure()
|
||||
logo = ScipyLogo((670, 250), 250)
|
||||
logo.plot_snake_curve()
|
||||
logo.plot_circle()
|
||||
img = io.imread('data/snake_pixabay.jpg')
|
||||
plt.imshow(img)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
plot_scipy_trace()
|
||||
plot_snake_overlay()
|
||||
|
||||
plt.show()
|
||||
@@ -1,16 +0,0 @@
|
||||
from skimage import io, transform
|
||||
|
||||
s = 0.7
|
||||
|
||||
img = io.imread('scikit_image_logo.png')
|
||||
h, w, c = img.shape
|
||||
|
||||
print "\nScaling down logo by %.1fx..." % s
|
||||
|
||||
img = transform.homography(img, [[s, 0, 0],
|
||||
[0, s, 0],
|
||||
[0, 0, 1]],
|
||||
output_shape=(int(h*s), int(w*s), 4),
|
||||
order=3)
|
||||
|
||||
io.imsave('scikit_image_logo_small.png', img)
|
||||
@@ -1,92 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="744.09448819"
|
||||
height="1052.3622047"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.1 r9760"
|
||||
sodipodi:docname="snake_logo.svg">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.98994949"
|
||||
inkscape:cx="161.85782"
|
||||
inkscape:cy="843.24881"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1280"
|
||||
inkscape:window-height="722"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="24"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<image
|
||||
sodipodi:absref="/home/stefan/src/scikits_image_logo/green_orange_snake.png"
|
||||
xlink:href="green_orange_snake.png"
|
||||
y="6.4703732"
|
||||
x="8.8462782"
|
||||
id="image3147"
|
||||
height="132.30446"
|
||||
width="132.30446" />
|
||||
<g
|
||||
id="g3158"
|
||||
transform="translate(-105.05586,-195.43585)">
|
||||
<text
|
||||
sodipodi:linespacing="125%"
|
||||
id="text3150"
|
||||
y="278.58533"
|
||||
x="261.22247"
|
||||
style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#4d4d4d;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
|
||||
xml:space="preserve"><tspan
|
||||
style="font-size:70px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:Ubuntu"
|
||||
y="278.58533"
|
||||
x="261.22247"
|
||||
id="tspan3152"
|
||||
sodipodi:role="line">scikit-image</tspan></text>
|
||||
<text
|
||||
sodipodi:linespacing="125%"
|
||||
id="text3154"
|
||||
y="306.86957"
|
||||
x="262.52374"
|
||||
style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#4d4d4d;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
|
||||
xml:space="preserve"><tspan
|
||||
style="font-size:26.5px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:Ubuntu"
|
||||
y="306.86957"
|
||||
x="262.52374"
|
||||
id="tspan3156"
|
||||
sodipodi:role="line">image processing in python</tspan></text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 3.3 KiB |
Reference in New Issue
Block a user