def test_imread_flatten(): # a color image is flattened and returned as float32 img = imread(os.path.join(data_dir, 'color.png'), flatten=True) assert img.dtype == np.float32 img = imread(os.path.join(data_dir, 'camera.png'), flatten=True) # check that flattening does not occur for an image that is grey already. assert np.sctype2char(img.dtype) in np.typecodes['AllInteger']
def test_imread_flatten(): # a color image is flattened img = imread(os.path.join(data_dir, 'color.png'), flatten=True) assert img.ndim == 2 assert img.dtype == np.float64 img = imread(os.path.join(data_dir, 'camera.png'), flatten=True) # check that flattening does not occur for an image that is grey already. assert np.sctype2char(img.dtype) in np.typecodes['AllInteger']
def main(): import scikits.image.io as io import sys if len(sys.argv) < 2: print "Usage: scivi <image-file> [<flip-file>]" sys.exit(-1) io.use_plugin('qt2') im = io.imread(sys.argv[1]) flip = None if len(sys.argv) > 2: flip = io.imread(sys.argv[2]) io.imshow(im, flip=flip, fancy=True) io.show()
def roundtrip(self, dtype, x, scaling=1): f = NamedTemporaryFile(suffix='.png') imsave(f.name, x) f.seek(0) y = imread(f.name) assert_array_almost_equal((x * scaling).astype(np.int32), y)
def roundtrip(self, dtype, x, scaling=1): f = NamedTemporaryFile(suffix='.png') fname = f.name f.close() imsave(fname, x) y = imread(fname) assert_array_almost_equal((x * scaling).astype(np.int32), y)
def plot_snake_overlay(): plt.figure() logo = ScipyLogo((670, 250), 250) logo.plot_snake_curve() logo.plot_circle() img = imgio.imread('data/snake_pixabay.jpg') #mask = logo.get_mask(img.shape, 'upper left') #img[mask] = 255 plt.imshow(img)
def main(): import scikits.image.io as io import sys if len(sys.argv) != 2: print "Usage: scivi <image-file>" sys.exit(-1) io.use_plugin("qt") io.imshow(io.imread(sys.argv[1]), fancy=True) io.show()
def main(): import scikits.image.io as io import sys if len(sys.argv) != 2: print "Usage: scivi <image-file>" sys.exit(-1) io.use_plugin('qt') io.imshow(io.imread(sys.argv[1]), fancy=True) io.show()
def __init__(self): self.radius = 250 self.origin = (420, 0) img = sio.imread('data/snake_pixabay.jpg') img = self._crop_image(img) img = img.astype(float) * 1.1 img[img > 255] = 255 self.img = img.astype(np.uint8) LogoBase.__init__(self)
def load_image(self, filename, var_name, dtype='uint8'): dt = np.uint8 if dtype == 'uint8': dt = np.uint8 elif dtype == 'float32': dt = np.float32 elif dtype == 'float64': dt = np.float64 elif dtype == 'int8': dt = np.int8 elif dtype == 'int32': dt = np.int32 filename = str(filename) var_name = str(var_name) arr = imread(os.path.join(self.folder, filename), dtype=dt) self.vars[var_name] = arr
import os import scikits.image as si import scikits.image.io as sio sio.use_plugin('matplotlib', 'imshow') sio.use_plugin('freeimage', 'imread') img = sio.imread(os.path.join(si.data_dir, 'color.png')) sio.imshow(img) sio.show()
def test_imread_palette(): img = imread(os.path.join(data_dir, 'palette_gray.png')) assert img.ndim == 2 img = imread(os.path.join(data_dir, 'palette_color.png')) assert img.ndim == 3
def test_read(self): io.imread('test.png', as_grey=True, dtype='i4', plugin='test')
# TODO: simpler imshow, without complete GUI return _advanced_imshow(im, flip=flip, mgr=mgr) def _advanced_imshow(im, flip=None, mgr=None): return AdvancedImageViewerApp(im, flip=flip, mgr=mgr) if __name__ == "__main__": from scikits.image.filter import tvdenoise from scikits.image.io import imread, imshow import numpy.random as npr import os, os.path import sys app = QApplication(sys.argv) if len(sys.argv) > 1: image = imread(sys.argv[1]) else: import scipy image = scipy.lena() flip = None if len(sys.argv) > 2: flip = imread(sys.argv[2]) viewer = _advanced_imshow(image, flip=flip, mgr=None) viewer.show() sys.exit(app.exec_())
# Source coordinates sc = np.array(plt.ginput(n=4)) screen_coords = [(0, 0), (1023, 0), (1023, 767), (0, 767)] # Homography: source to camera H_SC = estimate_homography(screen_coords, sc) tc = np.array(plt.ginput(n=4)) print tc tc_in_screen = \ np.dot(np.linalg.inv(H_SC), np.hstack((tc, np.ones((4,1)))).T).T tc_in_screen /= tc_in_screen[:, 2, np.newaxis] # Screen to screen homography H_SS = estimate_homography(screen_coords, tc_in_screen) grid = sio.imread('fatgrid.jpg') grid_warp = tf.homography(grid, H_SS, output_shape=grid.shape, order=2) np.save('/tmp/H_SS.npy', H_SS) sio.imsave('/tmp/grid_warp.png', grid_warp)
def test_imread_simple(): io.use_plugin('fits') testfile = os.path.join(data_dir, 'simple.fits') img = io.imread(testfile) assert np.all(img == pyfits.getdata(testfile, 0))
self.setTextSizeMultiplier(m) elif control and c == Qt.Key_0: self.setTextSizeMultiplier(1.05) if __name__ == "__main__": folder = "image_denoising_tutorial" if len(sys.argv) > 1: folder = sys.argv[1] app = QApplication(sys.argv) if False: viewer = WebImageViewer() image = imread(folder+'/data/lena512.tif') image_noise = image + npr.randn(image.size).reshape(image.shape)*29 viewer.show_image(image, image_noise) viewer.show() else: global_settings = QWebSettings.globalSettings() global_settings.setAttribute(QWebSettings.PluginsEnabled, True) view = Browser(folder) page = view.page() frame = page.mainFrame() factory = WebPluginFactory(frame) page.setPluginFactory(factory) window = QMainWindow()
def test_imread_simple(): io.use_plugin('fits') testfile = os.path.join(data_dir, 'simple.fits') img = io.imread(testfile) assert np.all(img==pyfits.getdata(testfile, 0))
class TestColorconv(TestCase): img_rgb = imread(os.path.join(data_dir, 'color.png')) img_grayscale = imread(os.path.join(data_dir, 'camera.png')) colbars = np.array([[1, 1, 0, 0, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0]]) colbars_array = np.swapaxes(colbars.reshape(3, 4, 2), 0, 2) colbars_point75 = colbars * 0.75 colbars_point75_array = np.swapaxes(colbars_point75.reshape(3, 4, 2), 0, 2) # RGB to HSV def test_rgb2hsv_conversion(self): rgb = self.img_rgb.astype("float32")[::16, ::16] hsv = rgb2hsv(rgb).reshape(-1, 3) # ground truth from colorsys gt = np.array([ colorsys.rgb_to_hsv(pt[0], pt[1], pt[2]) for pt in rgb.reshape(-1, 3) ]) assert_almost_equal(hsv, gt) def test_rgb2hsv_error_grayscale(self): self.assertRaises(ValueError, rgb2hsv, self.img_grayscale) def test_rgb2hsv_error_one_element(self): self.assertRaises(ValueError, rgb2hsv, self.img_rgb[0, 0]) # HSV to RGB def test_hsv2rgb_conversion(self): rgb = self.img_rgb.astype("float32")[::16, ::16] # create HSV image with colorsys hsv = np.array([ colorsys.rgb_to_hsv(pt[0], pt[1], pt[2]) for pt in rgb.reshape(-1, 3) ]).reshape(rgb.shape) # convert back to RGB and compare with original. # relative precision for RGB -> HSV roundtrip is about 1e-6 assert_almost_equal(rgb, hsv2rgb(hsv), decimal=4) def test_hsv2rgb_error_grayscale(self): self.assertRaises(ValueError, hsv2rgb, self.img_grayscale) def test_hsv2rgb_error_one_element(self): self.assertRaises(ValueError, hsv2rgb, self.img_rgb[0, 0]) # RGB to XYZ def test_rgb2xyz_conversion(self): gt = np.array([[[0.950456, 1., 1.088754], [0.538003, 0.787329, 1.06942], [0.592876, 0.28484, 0.969561], [0.180423, 0.072169, 0.950227]], [[0.770033, 0.927831, 0.138527], [0.35758, 0.71516, 0.119193], [0.412453, 0.212671, 0.019334], [0., 0., 0.]]]) assert_almost_equal(rgb2xyz(self.colbars_array), gt) # stop repeating the "raises" checks for all other functions that are # implemented with color._convert() def test_rgb2xyz_error_grayscale(self): self.assertRaises(ValueError, rgb2xyz, self.img_grayscale) def test_rgb2xyz_error_one_element(self): self.assertRaises(ValueError, rgb2xyz, self.img_rgb[0, 0]) # XYZ to RGB def test_xyz2rgb_conversion(self): # only roundtrip test, we checked rgb2xyz above already assert_almost_equal(xyz2rgb(rgb2xyz(self.colbars_array)), self.colbars_array) # RGB to RGB CIE def test_rgb2rgbcie_conversion(self): gt = np.array([[[0.1488856, 0.18288098, 0.19277574], [0.01163224, 0.16649536, 0.18948516], [0.12259182, 0.03308008, 0.17298223], [-0.01466154, 0.01669446, 0.16969164]], [[0.16354714, 0.16618652, 0.0230841], [0.02629378, 0.1498009, 0.01979351], [0.13725336, 0.01638562, 0.00329059], [0., 0., 0.]]]) assert_almost_equal(rgb2rgbcie(self.colbars_array), gt) # RGB CIE to RGB def test_rgbcie2rgb_conversion(self): # only roundtrip test, we checked rgb2rgbcie above already assert_almost_equal(rgbcie2rgb(rgb2rgbcie(self.colbars_array)), self.colbars_array) def test_convert_colorspace(self): colspaces = ['HSV', 'RGB CIE', 'XYZ'] colfuncs_from = [hsv2rgb, rgbcie2rgb, xyz2rgb] colfuncs_to = [rgb2hsv, rgb2rgbcie, rgb2xyz] assert_almost_equal( convert_colorspace(self.colbars_array, 'RGB', 'RGB'), self.colbars_array) for i, space in enumerate(colspaces): gt = colfuncs_from[i](self.colbars_array) assert_almost_equal( convert_colorspace(self.colbars_array, space, 'RGB'), gt) gt = colfuncs_to[i](self.colbars_array) assert_almost_equal( convert_colorspace(self.colbars_array, 'RGB', space), gt) self.assertRaises(ValueError, convert_colorspace, self.colbars_array, 'nokey', 'XYZ') self.assertRaises(ValueError, convert_colorspace, self.colbars_array, 'RGB', 'nokey') def test_rgb2grey(self): x = np.array([1, 1, 1]).reshape((1, 1, 3)) g = rgb2grey(x) assert_array_almost_equal(g, 1) assert_equal(g.shape, (1, 1))
from scikits.image import io, transform s = 0.7 img = io.imread('scikits_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('scikits_image_logo_small.png', img)
def __init__(self): self.radius = 250 self.origin = (420, 0) img = imgio.imread('data/snake_pixabay.jpg') self.img = self._crop_image(img) LogoBase.__init__(self)
def plot_image(self, **kwargs): ax = kwargs.pop('ax', plt.gca()) img = imgio.imread('data/scipy.png') ax.imshow(img, **kwargs)
def test_read(self): io.imread("test.png", as_grey=True, dtype="i4", plugin="test")
indxs = shift.astype(np.int); bincount = np.bincount(indxs); map[:len(bincount),i] = bincount return map,theta,bins; if __name__ == '__main__': if len(sys.argv)==1: print "\nUsage: %s <binary_image> [back_image] "; sys.exit(1); img_bin = io.imread(sys.argv[1]); try: img = io.imread(sys.argv[2]); except: img = None; theta = np.linspace(-np.pi,np.pi,90); coeffs,theta,bins = hough(img_edge,theta); rav_indxs = coeffs.argsort(axis=None)[-15:]; bin_theta_indxs = [ np.unravel_index(i,coeffs.shape) for i in rav_indxs ]; pts = []; for bin_idx,theta_idx in bin_theta_indxs:
def test_imread_MEF(): io.use_plugin('fits') testfile = os.path.join(data_dir, 'multi.fits') img = io.imread(testfile) assert np.all(img == pyfits.getdata(testfile, 1))
self.axes = axes axes.add_patch(self.patch) def paint(self): self.patch.set_x(self.x) self.patch.set_y(self.y) # This is probably not the right call. Should call redraw on canvas? plt.draw() print self.name for fn in args: try: img = sio.imread(fn, as_grey=True)/255. except IOError: print "Could not open file '%s'." % fn continue plt.imshow(img, cmap=plt.cm.gray) c = Canvas(name=('.'.join(fn.split('.')[:-1]).split('/')[-1]), img=img, patch_size=SIZE, axes=plt.gca()) plt.title('Click anywhere to move the region of interest. Press any "c" ' 'to crop.') plt.connect('key_press_event', crop_factory(c)) plt.connect('button_press_event', set_roi_factory(c)) plt.show()
def test_imread_dtype(): img = imread(os.path.join(data_dir, 'camera.png'), dtype=np.float64) assert img.dtype == np.float64
self.axes = axes axes.add_patch(self.patch) def paint(self): self.patch.set_x(self.x) self.patch.set_y(self.y) # This is probably not the right call. Should call redraw on canvas? plt.draw() print self.name for fn in args: try: img = sio.imread(fn, as_grey=True) / 255. except IOError: print "Could not open file '%s'." % fn continue plt.imshow(img, cmap=plt.cm.gray) c = Canvas(name=('.'.join(fn.split('.')[:-1]).split('/')[-1]), img=img, patch_size=SIZE, axes=plt.gca()) plt.title('Click anywhere to move the region of interest. Press any "c" ' 'to crop.') plt.connect('key_press_event', crop_factory(c)) plt.connect('button_press_event', set_roi_factory(c)) plt.show()
def test_imread_MEF(): io.use_plugin('fits') testfile = os.path.join(data_dir, 'multi.fits') img = io.imread(testfile) assert np.all(img==pyfits.getdata(testfile, 1))