Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize histogram normalization in C++

Shulou Source: shulou.com Published: 2022-06-01 05:51:40 09月11日 Update

This article mainly explains "how to achieve histogram normalization in C++". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "C++ how to achieve histogram normalization" bar!

Image processing 100 questions, this project really contains 100 questions that directly hit your weak foundation, which can help you improve a lot of knowledge loopholes and misunderstandings.

Just look at the catalog:

After intercepting three pictures, we should be able to see that his coverage is still very comprehensive. With python and C++ two sets of code, you can choose according to your own conditions.

Let's take a look at a random question:

The question is simple and straightforward, with a little bit of knowledge. The author of the project pursues a handwritten code implementation instead of simply calling an API of opencv. You can see the answer to this question:

C++ version:

# include # include / / histogram normalizationcv::Mat histogram_normalization (cv::Mat img, int a, int b) {/ / get height and width int width = img.cols; int height = 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; yearly +) {for (int x = 0; x < width; x +) {for (int _ c = 0; _ c < channel; _ C++) {val = (float) img.at (y, x) [c]; c = fmin (c, val); d = fmax (d, val);}

/ / histogram transformation for (int y = 0; y < height; yearly +) {for (int x = 0; x < width; xylene +) {for (int _ c = 0; _ c < 3; _ C++) {val = img.at (y, x) [_ c]

If (val < a) {out.at (y, x) [c] = (uchar) a;} else if (val b] = b out = out.astype (np.uint8)

Return out

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

# histogram normalizationout = hist_normalization (img)

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

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

At this point, I believe that "C++ how to achieve histogram normalization" have a deeper understanding, you might as well to practice it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Caching histogram problem code content knowledge project learning practical deeper weak author interest image image processing practicality practicality foundation simple operation method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Docker Linux Shulou Technology