Image Enhancement ︱window7+opencv3.2+keras/theano Simple application (function interpretation)

Source: Internet
Author: User
Tags theano keras

Installing OPENCV on the server encountered a problem with CUDA8.0, and had to see if other machines could be preinstalled and used.
.

First, python+opencv3.2 installation

OpenCV Why is it so easy to install in Windows?
Installation process:
1. Download OpenCV file Opencv-3.2.0-vc14.exe
2, click to download, in fact, is the decompression process, casually placed in a plate inside.
3, the Python deployment phase,
Go to OPENCV installation directory to find + copy: \build\python\2.7\x64\cv2.pyd
Copy Cv2.pyd to Python subdirectory: \lib\site-packages\
4, you can call directly:

import cv2

.

Second, Windows+keras/theano

Keras Deep Learning Framework is based on the Theano or TensorFlow framework installation, so first to prepare the bottom frame of the building, with TensorFlow more trouble, so choose Theano installation can.

1. Tensorflow/keras Frame

You can also use Anaconda 3.5 if you want to use tensorflow0.12 version +python3.5 and above.
A better way to use Docker:
Reference: TensorFlow Official documents Chinese version, download and installation

If you want to use a native window installation:

    • (1) Premise: The existing python3.5 or Anaconda 3.5
    • (2) Download: TENSORFLOW-0.12.0RC0-CP35-CP35M-WIN_AMD64.WHL, download something in a folder
    • (3) Enter the following command in the power Shell to implement the local installation:
pip install F:\DevResources\tensorflow_gpu-0.12.0rc0-cp35-cp35m-win_amd64.whl
    • (4) Verifying the installation

Under "All Programs" find "Python 3.5 64bit", a command window appears, enter the test code:

as tf>>>sess = tf.Session()>>>a = tf.constant(10)>>>b = tf.constant(22)>>>print(sess.run(a + b))32

The correct output of 32 is the successful installation.

Error not normal download NumPy 1.11.0: Reference blog: Native Windows installation TensorFlow 0.12 method
.

2. Theano/keras Frame

Installation process:

    • (1) Install Theano,power Shell input:
pipinstalltheano-U--pre
    • (2) Installation Keras:
pipinstallkeras-U--pre
    • (3) Modify the default backend: critical, otherwise it will always error: Importerror:no module named TensorFlow
      Because the Keras default backend is for TensorFlow,
      Open the C:\Users\ current user name. Keras, modify the Keras.json file in the folder as follows:
{"image_dim_ordering":"th","epsilon":1e-07,"floatx":"float32","backend":"theano"}
    • (4) Verifying the installation
>>>import kerasUsing Theano(Tensorflow) backend.>>>

Of course, there is also the Theano acceleration mode, which can be consulted: Keras Installation and Configuration Guide (Windows)
.

Third, image enhancement with Python+keras/theano (Data augmentation) 1, the way of image enhancement

Here are a total of 8 ways to transform images:

    • Rotation | Reflection Transformation (rotation/reflection): Random rotation of the image at a certain angle; Change the orientation of the image content;
    • Flip transform: Flips the image along a horizontal or vertical direction;
    • Zoom transform (ZOOM): Enlarge or reduce the image according to a certain proportion;
    • Translation Transformation (SHIFT): The image is translated in a certain way on the image plane; The panning range and the length of the shift can be specified in a random or man-defined way,
      Pan in a horizontal or vertical direction. Change the location of the image content;
    • Scale transformation: Enlarges or shrinks the image according to the specified scale factor; or by referring to sift features to extract ideas,
      The scale space of image filtering is constructed by using the specified scale factor. Change the size or the degree of ambiguity of the image content;
    • Contrast transform (contrast): In the HSV color space of the image, change the saturation s and v luminance components, keeping the hue H constant.
      Exponential operation of the S and V components of each pixel (exponential factor between 0.25 and 4) to increase illumination variation;
    • Noise Disturbance (Noise): random disturbance of RGB of each pixel of image, common noise pattern is salt and pepper noise and Gaussian noise;
    • Color transform: PCA in the RGB color space of the training set pixel value, resulting in 3 main vector of RGB space, 3 eigenvalues
      .
2. Image enhancement Cases

Online there is a very wide range of routines, referring to the blog "Deep Learning Data augmentation method and code implementation", "deep learning in the enhancement of the implementation of information augmentation", "keras Chinese document-image preprocessing":

 fromKeras.preprocessing.imageImportImagedatagenerator, Array_to_img, Img_to_array, load_img# Main Enhancement functionsDataGen = Imagedatagenerator (rotation_range=0.2,# Integer, rotation range, random rotation (0-180) degreesWidth_shift_range=0.2,# floating point, horizontal panning with a percentage of the length and width of the image for the range of changesHeight_shift_range=0.2,# floating-point numbers, which are shifted vertically by a percentage of the image's length and widthShear_range=0.2,# floating point, horizontal or vertical projection transformationZoom_range=0.2,# floating point, Random scale amplitude, [lower,upper] = [1-zoom_range, 1+zoom_range]horizontal_flip=True,# Boolean value, random horizontal flipFill_mode=' nearest ')# fill pixels, out of bounds, there are four ways: ' constant ', ' nearest ', ' reflect ', ' wrap '# featurewise_center=true # to center the input dataset (mean 0)# featurewise_std_normalization=true #将输入除以数据集的标准差以完成标准化# rescale=1./255, #重放缩因子, default is None. If none or 0 is not indented, the value is multiplied on the data (before other transformations are applied)# zca_whitening=true #对输入数据施加ZCA白化# channel_shift_range=0.2 #随机通道偏移的幅度# vertical_flip=true #布尔值, random vertical flip#数据导入img = load_img (' c:\\users\\desktop\\003.jpg ') x = Img_to_array (img) x = X.reshape ((1,) + X.shape)# The. Flow () command below generates batches of randomly transformed images# and saves the results to the ' preview/' directoryi =0 forBatchinchDatagen.flow (x, batch_size=1, save_to_dir=' C:\\users\\desktop ',#存放文件夹save_prefix=' Lena ',#存放文件名字save_format=' jpg '): i + =1    ifi > -: Break 

which
Imagedatagenerator is the main function of image enhancement, which contains many types of enhancement methods.
Load_img, Img_to_array, x.reshape image loading functions
Datagen.flow, enhanced execution function

which

    • load_img function:
load_img(path, grayscale=False, target_size=None)#path:图像载入的路径#grayscale:是否只载入灰度,默认为false#target_size:是否需要重新框定大小,默认是原图大小,其中如果要修改,则类似:image.load_img(img_path, target_size=(224224))
    • Img_to_array function:
img_to_array(img, dim_ordering=‘default‘)#img,load_img之后的内容#dim_ordering,图像的格式是否更改,一般是default,不做任何更改

function Source Source: https://github.com/fchollet/keras/blob/master/keras/preprocessing/image.py

Image Enhancement ︱window7+opencv3.2+keras/theano Simple application (function interpretation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.