Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新数字电路和计算机视觉资料 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 数字电路/实验指导.pdf
Binary file not shown.
Binary file added 数字电路/教材.pdf
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.25)
project(cv)

set(OpenCV_DIR C:/opencv/opencv/build)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 17)

add_executable(
cv
main.cpp
src/ImageProcess.cpp
include/ImageProcess.h
)
target_link_libraries(cv ${OpenCV_LIBS})
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Created by pc on 2024/4/8.
//
#include <opencv2/opencv.hpp>

#ifndef CV_IMAGEPROCESS_H
#define CV_IMAGEPROCESS_H
namespace ImgProcess {
// 获取直方图
float* getHist(cv::Mat img);
// 归一化直方图
void normalizeHist(float* hist);
// 获取累积分布函数
float* getCDF(float* hist);
// 直方图均衡化
void equalizeHist(cv::Mat img, cv::Mat& equalized_img);
// 伽马变换
void powerTransform(cv::Mat img, cv::Mat& power_img, float gamma, float c = 1.0);
}
#endif //CV_IMAGEPROCESS_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Created by: Pur1fy
Date: 2024/4/8
Author: 周睿星
学号:2022280486
Description: This is a simple example of using the ImageProcess class to perform power transformation and histogram equalization on an image.
*/
#include "include/ImageProcess.h"
using namespace cv;

int main() {
Mat img = imread("../images/car_3.jpg", IMREAD_GRAYSCALE);
Mat power_img;
Mat equalized_img;
ImgProcess::powerTransform(img, power_img, 0.5);
ImgProcess::equalizeHist(img, equalized_img);
imshow("Power Img", power_img);
imshow("Origin Img", img);
imshow("Equalized Img", equalized_img);
waitKey(0);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Created by pc on 2024/4/8.
//
#include "../include/ImageProcess.h"

namespace ImgProcess {
// 获取直方图
float* getHist(cv::Mat img) {
// 像素值范围0-255
int histSize = 256;
float* hist = (float*)malloc(sizeof(float) * histSize);
memset(hist, 0, sizeof(float) * histSize);
// 遍历图像,统计每个像素值的个数
for (int i = 0; i < img.rows; i++) {
for (int j = 0; j < img.cols; j++) {
hist[img.at<uchar>(i, j)]++;
}
}
return hist;
}
void normalizeHist(float* hist) {
float sum = 0;
for (int i = 0; i < 256; i++) {
sum += hist[i];
}
for (int i = 0; i < 256; i++) {
hist[i] /= sum;
}
}
// 获取累积分布函数
float* getCDF(float* hist) {
float* cdf = (float*)malloc(sizeof(float) * 256);
cdf[0] = hist[0];
for (int i = 1; i < 256; i++) {
// 累积分布函数求法:前一个像素的累积分布函数值+当前像素的概率
cdf[i] = cdf[i - 1] + hist[i];
}
return cdf;
}
void equalizeHist(cv::Mat img, cv::Mat& equalized_img) {
float* hist = getHist(img);
normalizeHist(hist);
float* cdf = getCDF(hist);
equalized_img = img.clone();
for (int i = 0; i < img.rows; i++) {
for (int j = 0; j < img.cols; j++) {
// 像素值映射 原像素 --> cdf[原像素] * 255
equalized_img.at<uchar>(i, j) = cdf[img.at<uchar>(i, j)] * 255;
}
}
free(hist);
free(cdf);
}
void powerTransform(cv::Mat img, cv::Mat& power_img, float gamma, float c) {
power_img = img.clone();
float L = 255;
for (int i = 0; i < img.rows; i++) {
for (int j = 0; j < img.cols; j++) {
// 像素值映射 原像素 --> c * (原像素 / L ) ^ gamma * L
power_img.at<uchar>(i, j) = c * pow(img.at<uchar>(i, j) / L, gamma) * L;
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading