{ "cells": [ { "cell_type": "markdown", "id": "f9c4296c-5816-4fcf-9ae2-88d6bb92f0f1", "metadata": { "tags": [] }, "source": [ "# 1.图像与矩阵" ] }, { "cell_type": "markdown", "id": "3bccfbd6-bf4f-45b9-b91d-a5b0ceaf07a3", "metadata": {}, "source": [ "## 图像实际是一个矩阵 \n", ">1.生成一个矩阵:二维数组 \n", ">2.保存矩阵为图像文件" ] }, { "cell_type": "code", "execution_count": null, "id": "5896de90-8cdf-4171-95cc-b3dcda6a1cc0", "metadata": {}, "outputs": [], "source": [ "import numpy # 向量与矩阵运算库(线性代数运算库) 1.19.5\n", "import cv2 # opencv-python opencv-contrib-python:图像处理\n", "# 生成数组\n", "img_array = [[[0, 255, 255, 50] for i in range(50)] for j in range(50)] # 255 * 255的图像,图像的像素[0, 255, 0, 128]\n", "# cv2中只支持numpy的格式\n", "img_numpy = numpy.array(img_array)\n", "cv2.imwrite(\"1.jpg\", img_numpy)" ] }, { "cell_type": "code", "execution_count": null, "id": "d786e85e-1271-4c24-a5fe-6f2cee1ce394", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }