前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【资源分享1】日本同行整理的视觉处理100问

【资源分享1】日本同行整理的视觉处理100问

作者头像
周旋
发布2020-07-06 17:42:37
4720
发布2020-07-06 17:42:37
举报
文章被收录于专栏:行走的机械人

今天介绍的是一位日本可爱的大佬的github项目,项目地址

代码语言:javascript
复制
https://github.com/gzr2017/ImageProcessing100Wen

图像处理100问,这个项目切切实实的包含了100个各种直击你薄弱底子的问题,看完可以帮你完善很多的知识漏洞和误区。

直接看看目录吧:

截取了三张,应该能看出他覆盖的还是很全面的了叭。附带python和c++两套代码,可以根据自己条件选择。

来随便找一个问题看看:

问题简单直接,还附带一点点知识点介绍,该项目作者本人奉行的是手写代码实现,而不是简单的调用一句opencv的API,可以看看这道题的答案:

C++版:

代码语言:javascript
复制
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <math.h>
// histogram normalization
cv::Mat histogram_normalization(cv::Mat img, int a, int b){
  // get height and width
  int width = img.cols;
  int height = img.rows;
  int channel = img.channels();

  int c, d;
  int val;

  // prepare output
  cv::Mat out = cv::Mat::zeros(height, width, CV_8UC3);

  // get [c, d]
  for (int y = 0; y < height; y++){
    for (int x = 0; x < width; x++){
      for (int _c = 0; _c < channel; _c++){
        val = (float)img.at<cv::Vec3b>(y, x)[_c];
        c = fmin(c, val);
        d = fmax(d, val);
      }
    }
  }

  // histogram transformation
  for (int y = 0; y < height; y++){
    for ( int x = 0; x < width; x++){
      for ( int _c = 0; _c < 3; _c++){
        val = img.at<cv::Vec3b>(y, x)[_c];

        if (val < a){
          out.at<cv::Vec3b>(y, x)[_c] = (uchar)a;
        }
        else if (val <= b){
          out.at<cv::Vec3b>(y, x)[_c] = (uchar)((b - a) / (d - c) * (val - c) + a);
        }
        else {
          out.at<cv::Vec3b>(y, x)[_c] = (uchar)b;
        }
      }
    }
  }

  return out;
}

int main(int argc, const char* argv[]){
  // read image
  cv::Mat img = cv::imread("imori_dark.jpg", cv::IMREAD_COLOR);

  // histogram normalization
  cv::Mat out = histogram_normalization(img, 0, 255);

  //cv::imwrite("out.jpg", out);
  cv::imshow("answer", out);
  cv::waitKey(0);
  cv::destroyAllWindows();

  return 0;
}

python版本:

代码语言:javascript
复制
import cv2
import numpy as np
import matplotlib.pyplot as plt

# histogram normalization
def hist_normalization(img, a=0, b=255):
  # get max and min
  c = img.min()
  d = img.max()

  out = img.copy()

  # normalization
  out = (b-a) / (d - c) * (out - c) + a
  out[out < a] = a
  out[out > b] = b
  out = out.astype(np.uint8)

  return out

# Read image
img = cv2.imread("imori_dark.jpg").astype(np.float)
H, W, C = img.shape

# histogram normalization
out = hist_normalization(img)

# Display histogram
plt.hist(out.ravel(), bins=255, rwidth=0.8, range=(0, 255))
plt.savefig("out_his.png")
plt.show()

# Save result
cv2.imshow("result", out)
cv2.waitKey(0)
cv2.imwrite("out.jpg", out)

纯手写实现,真的可以加深你对一个概念的理解。

最后再放一遍github地址:

https://github.com/gzr2017/ImageProcessing100Wen

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-07-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Opencv视觉实践 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档