Extract the Red lantern inside the image (ii)

Source: Internet
Author: User

First, the image is processed in a simple threshold:

/************************************************************** function: Extraction of red lantern in the image HSI space input parameters: source image src; Target image des ; image parameter width,height,nchannels; output parameter: Target image **************************************************************/void Hsi_ SEG (unsigned char* des, const unsigned char* src, int width, int height, int nchannels) {printf ("%d,%d,%d,", Nchannels,width  , height); unsigned char* OCL = new unsigned char[width * height * nchannels];unsigned char* HSI = new unsigned char[width *  Height * NCHANNELS];RGB_HSI (hsi,src, width, height, nchannels),//HSI component extraction for (int y = 0; y < height; y++) {for (int x = 0; x < width; X + +) {int img_h= hsi[y * Width * nchannels + x * nchannels]; int img_s= hsi[y * Width * nchannels + x * nchannels + 1]; in T img_i= hsi[y * Width * nchannels + x * nchannels + 2]; if (img_h<104) && (img_h>102) && (img_i>40) &  amp;& (img_s>60)) {//printf ("%d,", img_s); for (int n=0;n<nchannels;n++) des[y * Width * nchannels + x * nchannels + N] = src[y * Width * nchannels + x * NchanNels + n];} elsefor (int n=0;n<nchannels;n++) des[y * Width * nchannels + x * nchannels + n] = 255;}} Imagedilation (Ocl, des, width, height, nchannels,3);//template expansion for 3*3

  

Extract the red component as shown, and then do the expansion of the 3*3 template again:

Once again corrosion and fill, the effect is as follows:

Here is the code for the image fill:

void Imgfill (unsigned char* des, const unsigned char* src, int width, int height, int nchannels) {memcpy (DES, SRC, nchannel S*width*height);//TODO: This adds the command handler code//record fills the leftmost position of the row int left_x=0;//record fills the right-most position of the row int right_x=0;//record fills the top position of the column int top_y=0;// Record padding column's bottom position int bottom_y=0;//landscape fill for (int y=0;y

  

Another 8*8 of corrosion and 5*5 expansion:

Finally reconstruct the image:

Second, to the large window area shadow enhancement
/************************************************************** function: Histogram equalization for Image window shadows input parameters: source image src; Target image des ; image parameter width,height,nchannels; output parameter: Target image **************************************************************/void Win_ Enhance (unsigned char* des, const unsigned char* src, int width, int height, int nchannels) {printf ("%d,%d,%d,", nchannels,w idth,height); unsigned char* OCL = new unsigned char[width * height * nchannels];unsigned char* flag = new unsigned Char[wi DTH * Height * nchannels];int r[256] = {0}, g[256] = {0}, b[256] = {0};int sum = 0; Synthesis of pixel points in the image for (int y = 0; y < height; y++) {for (int x = 0; x < width; x + +) {int b= src[y * Width * nchannels + x * nCh Annels]; int g= src[y * Width * nchannels + x * nchannels + 1]; int r= src[y * Width * nchannels + x * nchannels + 2]; if ((r+g+b<120) && (Y < height-240) && (y >250)) {//printf ("%d,", img_s); for (int n=0;n<nchannels;n++) {des[y * Width * nchannels + x * nchannels + N] = src[y * Width * n Channels + x * nchannels + n] ;}} else{for (int n=0;n<nchannels;n++) {des[y * Width * nchannels + x * nchannels + n] = 255;}}} Imageerosion (Ocl, des, width, height, nchannels,9), Imagedilation (DES, OCL, width, height, nchannels,10);

  

After a simple threshold processing, a 9*9 corrosion and a 10*10 expansion diagram are performed:

The histogram equalization for the shaded area is as follows:

memcpy (OCL, des,nchannels*width*height); for (int. y=0; y

  

The final effect is as follows:

Extract the Red lantern inside the image (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.