Example of how to adjust the color gradient of PS Images Using Python, python gradient

Source: Internet
Author: User

Example of how to adjust the color gradient of PS Images Using Python, python gradient

This article describes how to adjust the color gradient of PS Images Using Python. We will share this with you for your reference. The details are as follows:

Here, we use Python to implement a color chart in PS. You can see various gradient colors. For more information about the effects, see the appendix.

Compared with the previous program, the matrix operation is used to replace the for loop, improving the running efficiency.

import numpy as npimport matplotlib.pyplot as pltfrom skimage import ioimport numpy.matlibfrom skimage import img_as_floatfile_name='D:/Visual Effects/PS Algorithm/4.jpg';img=io.imread(file_name)img = img_as_float(img)row, col, channel = img.shaperNW = 0.5rNE = 1.0rSW = 1.0rSE = 0.0gNW = 0.0gNE = 0.5gSW = 0.0gSE = 1.0bNW = 1.0bNE = 0.0bSW = 1.0bSE = 0.0xx = np.arange (col)yy = np.arange (row)x_mask = numpy.matlib.repmat (xx, row, 1)y_mask = numpy.matlib.repmat (yy, col, 1)y_mask = np.transpose(y_mask)fx = x_mask * 1.0 / colfy = y_mask * 1.0 / rowp = rNW + (rNE - rNW) * fxq = rSW + (rSE - rSW) * fxr = ( p + (q - p) * fy )r[r<0] = 0r[r>1] =1p = gNW + (gNE - gNW) * fxq = gSW + (gSE - gSW) * fxg = ( p + (q - p) * fy )g[g<0] = 0g[g>1] =1p = bNW + (bNE - bNW) * fxq = bSW + (bSE - bSW) * fxb = ( p + (q - p) * fy )b[b<0] = 0.0b[b>1] = 1.0img[:, :, 0] = rimg[:, :, 1] = gimg[:, :, 2] = bplt.figure(1)plt.imshow(img)plt.axis('off');plt.show();

Appendix: PS-color gradient

  clc;  clear all;  close all;  addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');  I=imread('4.jpg');  Image=double(I)/255;  [height, width, depth]=size(Image);  rNW=1.0;   gNW=0.0;  bNW=0.0;  rNE=1.0;   gNE=1.0;  bNE=0.0;  rSW=0.0;   gSW=0;   bSW=1.0;  rSE=0.0;   gSE=1.0;  bSE=0.0;  Img_new=Image;  for ii=1:height    for jj=1:width      fx = jj / width;      fy = ii / height;      p = rNW + (rNE - rNW) * fx;      q = rSW + (rSE - rSW) * fx;      r = ( p + (q - p) * fy );      r = min(max(r, 0), 1);      p = gNW + (gNE - gNW) * fx;      q = gSW + (gSE - gSW) * fx;      g = ( p + (q - p) * fy );      g = min(max(g, 0) ,1);      p = bNW + (bNE - bNW) * fx;      q = bSW + (bSE - bSW) * fx;      b = ( p + (q - p) * fy );      b = min(max(b, 0), 1);      Img_new(ii, jj, 1)=r;      Img_new(ii, jj, 2)=g;      Img_new(ii, jj, 3)=b;    end    end  imshow(Img_new);  imwrite(Img_new, 'out.jpg');

Reference Source: http://www.jhlabs.com/index.html

In this example, run Python:

Source image:

Running effect:

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.