# 图像基础处理 **Repository Path**: li-meng-yan01/image-basic-processing ## Basic Information - **Project Name**: 图像基础处理 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-01 - **Last Updated**: 2025-10-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 图像处理实验代码说明(README) 本项目包含若干基于 Python 的图像处理实验代码,主要使用 `skimage`、`matplotlib` 和 `numpy` 等库,针对不同图片进行像素级操作和可视化。以下为各代码单元的详细说明: ## 依赖环境 - Python 3.x - scikit-image(skimage) - matplotlib - numpy 建议使用 Jupyter Notebook 运行本项目。 ## 文件说明 - `x.jpg`、`galaxy-full.jpg`、`earth.jpg`:实验用图片文件,需与代码在同一目录下。 - `Untitled15.ipynb`:主实验代码文件。 ## 代码单元详解 ### 1. 基础图片读取与显示 ```python from skimage import io # 导入图像读取模块 import matplotlib.pyplot as plt # 导入绘图库 img = io.imread('x.jpg') # 读取图片 plt.imshow(img) plt.show() ``` **功能**:读取并显示一张图片。 --- ### 2. 上半部分变红 ```python import numpy as np from skimage import io import matplotlib.pyplot as plt img = io.imread('x.jpg') half_height = img.shape[0] // 2 if len(img.shape) == 3 and img.shape[2] == 3: img[:half_height, :, 0] = 255 # 上半部分红色通道设为最大 plt.imshow(img) plt.axis('off') plt.show() ``` **功能**:将图片上半部分的红色通道设为最大值(变红)。 --- ### 3. 左半部分变红 ```python import numpy as np from skimage import io import matplotlib.pyplot as plt img = io.imread('x.jpg') half_width = img.shape[1] // 2 if len(img.shape) == 3 and img.shape[2] == 3: img[:, :half_width, 0] = 255 # 左半部分红色通道设为最大 plt.imshow(img) plt.axis('off') plt.show() ``` **功能**:将图片左半部分的红色通道设为最大值(变红)。 --- ### 4. 左上四分之一变红 ```python import numpy as np from skimage import io import matplotlib.pyplot as plt img = io.imread('x.jpg') height, width = img.shape[:2] top_half = height // 2 left_half = width // 2 if len(img.shape) == 3 and img.shape[2] == 3: img[:top_half, :left_half, 0] = 255 # 左上四分之一红色通道设为最大 plt.imshow(img) plt.axis('off') plt.show() ``` **功能**:将图片左上四分之一区域的红色通道设为最大值。 --- ### 5. 指定像素点变色(红/绿/蓝) ```python from skimage import io import matplotlib.pyplot as plt img = io.imread('x.jpg') print(img.shape) h, w, c = img.shape for i in range(3,7): for j in range(3,7): img[j, i][0] = 255 # 指定区域变红 plt.imshow(img) plt.show() ``` **功能**:将图片中 (3,3)-(6,6) 区域的像素红色通道设为最大。 --- ### 6. 指定像素点变色(绿/蓝) ```python from skimage import io import matplotlib.pyplot as plt img = io.imread('x.jpg') print(img.shape) h, w, c = img.shape for i in range(1,9): for j in range(1,9): img[j, i][1] = 255 # 绿色通道最大 img[j, i][2] = 0 # 蓝色通道最小 plt.imshow(img) plt.show() ``` **功能**:将图片中 (1,1)-(8,8) 区域的像素绿色通道设为最大,蓝色通道设为最小。 --- ### 7. galaxy-full.jpg 上半部分去绿蓝 ```python from skimage import io import matplotlib.pyplot as plt img = io.imread('galaxy-full.jpg') h, w, c = img.shape for i in range(w): for j in range(h): img[j, i][1] = 0 # 绿色通道最小 img[j, i][2] = 0 # 蓝色通道最小 plt.imshow(img) plt.show() ``` **功能**:将 galaxy-full.jpg 的所有像素绿色和蓝色通道设为 0。 --- ### 8. galaxy-full.jpg 上半部分去红蓝 ```python from skimage import io import matplotlib.pyplot as plt img = io.imread('galaxy-full.jpg') h, w, c = img.shape for i in range(w): for j in range(h): img[j, i][0] = 0 # 红色通道最小 img[j, i][2] = 0 # 蓝色通道最小 plt.imshow(img) plt.show() ``` **功能**:将 galaxy-full.jpg 的所有像素红色和蓝色通道设为 0。 --- ### 9. galaxy-full.jpg 上半部分去红绿 ```python from skimage import io import matplotlib.pyplot as plt img = io.imread('galaxy-full.jpg') h, w, c = img.shape for i in range(w): for j in range(h): img[j, i][0] = 0 # 红色通道最小 img[j, i][1] = 0 # 绿色通道最小 plt.imshow(img) plt.show() ``` **功能**:将 galaxy-full.jpg 的所有像素红色和绿色通道设为 0。 --- ### 10. earth.jpg 彩条效果 ```python from skimage import io import matplotlib.pyplot as plt img = io.imread('earth.jpg') h, w, c = img.shape for i in range(w): for j in range(h): if i%3==0: img[j, i][0] = 255 elif i%3==1: img[j, i][1] = 255 else: img[j, i][2] = 255 plt.figure(figsize=(15,15)) plt.imshow(img) plt.show() ``` **功能**:将 earth.jpg 按列分为红、绿、蓝三色条纹。 --- ## 运行方法 1. 确保所有图片文件与 notebook 在同一目录下。 2. 安装依赖库: ```bash pip install scikit-image matplotlib numpy ``` 3. 用 Jupyter Notebook 打开 `Untitled15.ipynb`,逐单元运行。 24级 智能科学与技术二班 李孟岩 202452320211