「机器视觉」学习笔记 - Constructing And Building Histograms

图像增强:

CLAHE Contrast Limited Adaptive Histogram Equalization

AHE adaptive histogram equalization

histogram equalization

  1. What is an image histogram?

  2. Calculate the histogram of a grayscale image using 64 bins.

  3. Add 50 to every pixel on a grayscale image (the result will look lighter) and calculate the histogram.

  4. Calculate the red channel histogram of a BGR image without a mask.

  5. What functions do OpenCV, NumPy, and Matplotlib provide for calculating histograms?

  6. Modify the grayscale_histogram.py script to compute the brightness of these three images (gray_image, added_image, and subtracted_image). Rename the script to grayscale_histogram_brightness.py.

  7. Modify the comparing_hist_equalization_clahe.py script to show the execution time of both cv2.equalizeHist() and CLAHE. Rename it to comparing_hist_equalization_clahe_time.py.

Mastering OpenCV 4 with Python

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, here's the code: ```cpp #include <iostream> #include <vector> #include <algorithm> using namespace std; void heapify(vector<int>& arr, int n, int i) { int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l < n && arr[l] > arr[largest]) largest = l; if (r < n && arr[r] > arr[largest]) largest = r; if (largest != i) { swap(arr[i], arr[largest]); heapify(arr, n, largest); } } void buildHeap(vector<int>& arr) { int n = arr.size(); for (int i = n / 2 - 1; i >= 0; i--) heapify(arr, n, i); } void printHeap(vector<int>& arr) { int n = arr.size(); int row = 1, col = 0; while (col < n) { for (int i = col; i < min(n, col + row); i++) cout << arr[i] << " "; cout << endl; col += row; row *= 2; } } int main() { vector<int> arr = { 4, 10, 3, 5, 1 }; buildHeap(arr); printHeap(arr); } ``` This program first constructs a max heap from a given vector of integers using the `buildHeap` function. It then prints the heap in a rotated format using the `printHeap` function. The `heapify` function is used to maintain the heap property while constructing the heap. It takes an array `arr`, its size `n`, and the index of the current node `i` as input. It compares the value at the current node with its left and right child nodes, and swaps the current node with the largest child node if necessary. It then recursively calls itself on the largest child node to maintain the heap property. The `buildHeap` function iterates over the second half of the array in reverse order (since these nodes are the ones with children) and calls `heapify` on each node to construct the heap. The `printHeap` function prints the heap in a rotated format. It first initializes the row and column numbers, and then iterates over each row of the heap, printing the nodes in that row and updating the column and row numbers accordingly. Note that this program assumes a complete binary tree representation of the heap. If the input vector is not complete, the program may produce unexpected results.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值