调整灰度图像的大小,而无需在Python中使用任何内置函数

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():
它以图像文件的绝对路径/相对路径作为参数,并返回其对应的图像矩阵。

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 attribute of an image matrix:

同样在此程序中,我们将使用图像矩阵的一个属性:

shape: This is the attribute of an image matrix which return shape of an image i.e. consisting of number of rows ,columns and number of planes.

形状:这是图像矩阵的属性,该属性返回图像的形状,即由行数,列数和平面数组成。

In the case of a Grayscale image, only one plane is needed. If the number of planes is 1 then shape attribute only return number of rows and columns.

在灰度图像的情况下,仅需要一个平面。 如果平面数为1,则shape属性仅返回行数和列数。

Also, here 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 : : 2])
Output:
[2, 4, 6, 9]

Python程序,无需使用任何内置函数即可调整灰度图像的大小 (Python program to resize a grayscale image without using any inbuilt functions )

# open-cv library is installed as cv2 in python
# import cv2 library into this program
import cv2
# give value by which you want to resize an image
# here we want to resize an image as one half of the original image
x,y= 2,2
# read an image using imread() function of cv2
# we have to  pass only the path of the image
img = cv2.imread(r'C:/Users/user/Desktop/pic2.jpg',0)
# displaying the image using imshow() function of cv2
# In this : 1st argument is name of the frame
# 2nd argument is the image matrix
cv2.imshow('original image',img)
# print shape of the image matrix
# using shape attribute
print("original image shape:",img.shape)
# here we take alternate row,column pixel.
# we take half pixel of rows and columns respectively
# so that it is one half of image matrix.
resize_img = img[::x,::y]
cv2.imshow('resize image',resize_img)
# print shape of the image matrix
# using shape attribute
print("resize image shape:",resize_img.shape)

Output

输出量

Resize a grayscale image in Python - output
Resize a grayscale imagein Python - output

翻译自: https://www.includehelp.com/python/resize-a-grayscale-image-without-using-any-inbuilt-functions.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546045.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第一章 认识计算机

*(%)^*&!*第一讲 了解计算机基础知识一、计算机的发展历程1、计算机的起源(1)世界上第一台计算机:1946年诞生,名称为ENIAC。(2)世界上第一台并行计算机:1950年诞生,名称为EDVAC&…

scoket多线程例子

大体思路,有n台mc,要dump出数据,n台进行对比,看数据是否一致,设计到同时dump的问题,server断发条指令给这n台mc,mc同时去dump把结果返回给server端,server端把这些结果进行对比serve…

csapp bufbomb实验

csapp (《深入理解计算机系统》&#xff09;一书中有一个关于缓冲区溢出的实验&#xff0c;其程序代码如下&#xff1a; /* Bomb program that is solved using a buffer overflow attack */#include <stdio.h> #include <stdlib.h> #include <ctype.h> #in…

漫画:对象是如何被找到的?句柄 OR 直接指针?

小贴士&#xff1a;想要使用并定位 Java 对象&#xff0c;就要用到 Java 虚拟机栈&#xff08;Java Virtual Machine Stack&#xff09;&#xff0c;它描述的是 Java 方法执行的线程内存模型&#xff1a;每个方法被执行的时候&#xff0c;Java 虚拟机都会同步创建一个栈帧&…

在C ++中检查一个数组是否是另一个数组的子数组

Prerequisite: std::equal() function 先决条件&#xff1a; std :: equal()函数 Problem statement: 问题陈述&#xff1a; Check if one array is subarray of another or not. 检查一个数组是否是另一个数组的子数组。 Example: 例&#xff1a; Input 1:Arr1 [3, 4, 5, …

第二章 认识计算机硬件

*(%)^*&!*第一讲 认识计算机主板一、主板的结构1、主板结构分类&#xff08;2&#xff09;AT、Baby-AT型&#xff08;2&#xff09;ATX型&#xff08;3&#xff09;Micro ATX板型&#xff08;4&#xff09;LPX、NLX、Flex ATX板型&#xff08;5&#xff09;EATX、WATX板型&…

IDEA 不为人知的 5 个骚技巧!真香!

工欲善其事&#xff0c;必先利其器&#xff0c;磊哥最近发现了几个特别棒的 IDEA“骚”技巧&#xff0c;已经迫不及待的想要分享给你了&#xff0c;快上车...1.快速补全行末分号使用快捷键 Shfit Ctrl Enter 轻松实现。2.自带的 HTTP 请求工具IDEA 自带了 HTTP 的测试工具&am…

教育编程语言(转)

这是wikipedia上的内容&#xff0c;转载保存&#xff0c;以便以后查阅&#xff0c;英文版见Educational programming language 主要是介绍了一些适合于教育的编程语言&#xff0c;分别适合于不同的个人需求。 详细内容如下&#xff1a; 许多教育性质的程序设计语言都提供建议…

JavaScript | 将十进制转换为十六进制,反之亦然

Sometimes we need to convert an integer value which is in decimal format to the hexadecimal string in JavaScript or need a decimal value from a given hexadecimal string. 有时&#xff0c;我们需要将十进制格式的整数值转换为JavaScript中的十六进制字符串&#xf…

漫画:Integer 竟然有 4 种比较方法?

代码测试public class IntegerTest {public static void main(String[] args) {Integer i1 127;Integer i2 127;System.out.println(i1 i2);Integer i3 128;Integer i4 128;System.out.println(i3 i4);} }以上代码的执行结果为&#xff1a;truefalse首先&#xff0c;当我…

第三章 组装个人计算机

*(%)^*&!*第一讲 选购个人计算机部件1、计算机配件选购的基本原则&#xff08;1&#xff09;组装电脑按需配置&#xff0c;明确电脑使用范围&#xff1b;&#xff08;2&#xff09;衡量装机预算&#xff1b;&#xff08;3&#xff09;衡量整机运行速度。2、电脑配件选购注意…

IP地址的分类——a,b,c 类是怎样划分的

如今的IP网络使用32位地址&#xff0c;以点分十进制表示&#xff0c;如172.16.0.0。地址格式为&#xff1a;IP地址网络地址&#xff0b;主机地址 或 IP地址主机地址&#xff0b;子网地址&#xff0b;主机地址。 IP地址类型 最初设计互联网络时&#xff0c;为了便于寻址以及层次…

《Introduction to Computing Systems: From bits and gates to C and beyond》

很好的一本计算机的入门书&#xff0c;被很多学校采纳作为教材&#xff0c;作者Yale N. Patt 是计算机界的泰斗。中文版名为《计算机系统概论》&#xff08;译者&#xff1a;梁阿磊 , 蒋兴昌, 林凌&#xff09; 书籍首页 (旧版首页 &#xff09; LC-3相关工具 LC-3Help 采…

在数组中查找第k个最大元素_查找数组中每个元素的最近最大邻居

在数组中查找第k个最大元素Problem statement: 问题陈述&#xff1a; Given an array of elements, find the nearest (on the right) greatest element ofeach element in the array. (Nearest greatest means the immediate greatest one on the right side). 给定一个元素数…

6种快速统计代码执行时间的方法,真香!(史上最全)

我们在日常开发中经常需要测试一些代码的执行时间&#xff0c;但又不想使用向 JMH&#xff08;Java Microbenchmark Harness&#xff0c;Java 微基准测试套件&#xff09;这么重的测试框架&#xff0c;所以本文就汇总了一些 Java 中比较常用的执行时间统计方法&#xff0c;总共…

fltk 库

fltk是一个小型、开源、支持OpenGL 、跨平台&#xff08;windows,linux,mac OSX)的GUI库&#xff0c;它兼容xforms 图形库&#xff08;unix/linux下的一个C语言图形库)&#xff0c;所以可以用来开发模块化的程序&#xff0c;同时也可以使用面向对象开发程序&#xff0c;使用起来…

人工智能ai 学习_人工智能中强化学习的要点

人工智能ai 学习As discussed earlier, in Reinforcement Learning, the agent takes decisions in order to attain maximum rewards. These rewards are the reinforcements through which the agent learns in this type of agent. 如前所述&#xff0c;在“ 强化学习”中 &…

第四章 计算机软件安装与调试

*(%)^*&!*第一讲 系统BIOS和CMOS参数设置&#xff08;1&#xff09;一、BIOS、CMOS的基本概念1.BIOS的含义BIOS是只读存储器基本输入/输出系统的简写&#xff0c;是被雇花道计算机主板ROM芯片上的一组程序&#xff0c;为计算机提供最低级、最直接的硬件控制。2.CMOS的含义C…

连夜整理了几个开源项目,毕设/练手/私活一条龙!

一直以来&#xff0c;总有小伙伴问说&#xff1a;诶&#xff0c;有没有什么好的项目推荐啊&#xff0c;想参考使用。一般用途无非如下几种情况&#xff1a;自学练手&#xff1a;从书本和博客的理论学习&#xff0c;过渡到实践练手吸收项目经验&#xff0c;找工作写简历时能参考…

MPI编程简单介绍

第三章 MPI编程 3.1 MPI简单介绍 多线程是一种便捷的模型&#xff0c;当中每一个线程都能够訪问其他线程的存储空间。因此&#xff0c;这样的模型仅仅能在共享存储系统之间移植。一般来讲&#xff0c;并行机不一定在各处理器之间共享存储&#xff0c;当面向非共享存储系统开发…