博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在Python中升级灰度图像
阅读量:2529 次
发布时间:2019-05-11

本文共 2867 字,大约阅读时间需要 9 分钟。

Upscaling of an image refers to enlarging the size of an image.

图像放大是指放大图像的大小。

In this program, we will be using two functions of OpenCV-python (cv2) module.. let's see their syntax and descriptions first

在此程序中,我们将使用OpenCV-python(cv2)模块的两个函数。.让我们首先查看它们的语法和描述。

1) imread():

It takes an absolute path/relative path of your image file as an argument and returns its corresponding image matrix.

1)imread():

它以图像文件的绝对路径/相对路径作为参数,并返回其对应的图像矩阵。

If flag value is:

如果标志值为:

  • 1: Loads a color image.

    1 :加载彩色图像。

  • 0: Loads image in grayscale mode.

    0 :以灰度模式加载图像。

  • -1: Loads image as such including alpha channel.

    -1 :加载图像,包括alpha通道。

If the flag value is not given then show the original image, which path is given.

如果未给出标志值,则显示原始图像,并给出哪个路径。

2) imshow():

It takes window name and image matrix as an argument in order to display an image in a display window with a specified window name.

2)imshow():

它以窗口名称和图像矩阵为参数,以便在具有指定窗口名称的显示窗口中显示图像。

Also In this program, we will be using one function of numpy module.

同样在此程序中,我们将使用numpy模块的一个功能。

median(): It takes array and returns the median of the array .

平均():它接受array并返回array的中位数。

Also, in this program we are using the concept of array slicing

另外,在此程序中,我们使用数组切片的概念

Let, A is 1-d array:

A[start:stop:step]

设A为一维数组:

A [开始:停止:步骤]

  1. start: Starting number of the sequence.

    start:序列的起始编号。

  2. stop: Generate numbers up to, but not including this number.

    停止:生成不超过此数字的数字,但不包括此数字。

  3. step: Difference between each number in the sequence.

    步骤:序列中每个数字之间的差。

Example:

例:

A = [1,2,3,4,5,6,7,8,9,10]    print(A[ 1: 5])    Output:    [2,3,4,5]

用于在Python中放大灰度图像的Python程序 (Python program for upscaling the grayscale image in Python)

# open-cv library is installed as cv2 in python# import cv2 library into this programimport cv2# import numpy as np nameimport numpy as np# read an image using imread() function of cv2# we have to  pass only the path of the imageimg = cv2.imread(r'C:/Users/user/Desktop/pic6.jpg',0)# displaying the image using imshow() function of cv2# In this : 1st argument is name of the frame# 2nd argument is the image matrixcv2.imshow('original image',img)# upscaling code# Upscaling the image x,y times along row and columnx,y = 2, 2# here image is of class 'uint8', the range of values  # that each colour component can have is [0 - 255]# create a zero matrix of order of x,y times# of previous image of 3-dimensionsupscale_img = np.zeros((x*img.shape[0],y*img.shape[1]),np.uint8)i, m = 0, 0while m < img.shape[0] :    j, n = 0, 0    while n < img.shape[1]:        # We assign pixel value from original image matrix to the        # new upscaling image matrix in alternate rows and columns        upscale_img[i, j] = img[m, n]        # increment j by y times        j += y        # increment n by one        n += 1    # increment m by one    m += 1    # increment i by x times    i += x   cv2.imshow('upscaling image',upscale_img)

Output

输出量

Upscaling the grayscale image in Python - output

翻译自:

转载地址:http://rkxzd.baihongyu.com/

你可能感兴趣的文章
使用JustDecompile修改程序集
查看>>
SQLServer 分组查询相邻两条记录的时间差
查看>>
Swift语言指南(一)--语言基础之常量和变量
查看>>
关于webpack的使用
查看>>
Windows 2008 R2上配置IIS7或IIS7.5中的URLRewrite(URL重写)实例
查看>>
浅析java垃圾回收机制
查看>>
彻底理解线性筛选法
查看>>
Java Socket总结
查看>>
法语学习笔记
查看>>
使用css的类名交集复合选择器 《转》
查看>>
[USACO18DEC]The Cow Gathering
查看>>
情感分析-英文电影评论
查看>>
王者荣耀游戏服务器架构的演进读后感
查看>>
关于ajax请求controller返回中文乱码的解决方法!
查看>>
Objective-C 和 Core Foundation 对象相互转换的内存管理总结
查看>>
IOS音频1:之采用四种方式播放音频文件(一)AudioToolbox AVFoundation OpenAL AUDIO QUEUE...
查看>>
Linux nmon 命令
查看>>
使用 urllib 构造请求对象
查看>>
sql server book
查看>>
长亭技术专栏 安全攻防技术分享
查看>>