In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the C language how to achieve BMP image closed operation processing, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The closed operation can take out the specific image details which are smaller than the structural elements, while ensuring that the global geometric distortion does not occur. Fill a gap or hole smaller than a structural element and connect it with short breaks.
Operation: that is, first expand and then erode.
# include # include # include int main (int* argc, char** argv) {FILE* fp = fopen (". / threshold.bmp", "rb"); if (fp = = 0) return 0; BITMAPFILEHEADER fileHead; fread (& fileHead, sizeof (BITMAPFILEHEADER), 1, fp); BITMAPINFOHEADER infoHead; fread (& infoHead, sizeof (BITMAPINFOHEADER), 1, fp); int width = infoHead.biWidth; int height = infoHead.biHeight; int biCount = infoHead.biBitCount; int lineByte = (biCount*width / 8 + 3) / 4 * 4; RGBQUAD* pColorTable PColorTable = new RGBQUAD; fread (pColorTable, sizeof (RGBQUAD), 256, fp); unsigned char* pBmpBuf; pBmpBuf = new unsigned char [lineByte*height]; fread (pBmpBuf, lineByte*height, 1, fp); fclose (fp); / / New figure FILE* fop = fopen ("close.bmp", "wb"); if (fop = 0) return 0; / / expansion operation / / initialization int t = 0, d = 0, r = 0; unsigned char* pBmpBuf2 PBmpBuf2 = new unsigned char [lineByte*height]; for (int I = 0; I
< height; ++i){ for (int j = 0; j < width; ++j){ *(pBmpBuf2 + i*lineByte + j) = 255; } } for (int i = 1; i < height; ++i){ for (int j = 0; j < width - 1; ++j){ t = *(pBmpBuf + i*lineByte + j); // 当前点 d = *(pBmpBuf + (i - 1)*lineByte + j); // 下面点 r = *(pBmpBuf + i*lineByte + j + 1); // 右边点 if (t == 0 && d == 0 && r == 0){ *(pBmpBuf2 + i*lineByte + j) = 0; // 当前点 } } } // 结构元素向上反转180度,对最下面一排处理 for (int j = 0; j < width - 1; ++j){ t = *(pBmpBuf + j); // 当前点 d = *(pBmpBuf + lineByte + j); // 上面点 r = *(pBmpBuf + j + 1); // 右边点 if (t == 0 && d == 0 && r == 0){ *(pBmpBuf2 + j) = 0; // 当前点 } } // 结构元素向右反转,对最右边一列处理 for (int i = 1; i < height; ++i){ t = *(pBmpBuf + i*lineByte + width - 1); d = *(pBmpBuf + (i - 1)*lineByte + width - 1); r = *(pBmpBuf + i*lineByte + width - 2); if (t == 0 && d == 0 && r == 0){ *(pBmpBuf2 + i*lineByte + width - 1) = 0; // 当前点 } } // 腐蚀操作 for (int i = 1; i < height; ++i){ for (int j = 0; j < width - 1; ++j){ t = *(pBmpBuf2 + i*lineByte + j); // 当前点 d = *(pBmpBuf2 + (i - 1)*lineByte + j); // 下面点 r = *(pBmpBuf2 + i*lineByte + j + 1); // 右边点 if (t == 0 && d != 0){ *(pBmpBuf2 + (i - 1)*lineByte + j) = 0;//下边的置位1 } if (t == 0 && r != 0){ *(pBmpBuf2 + i*lineByte + j + 1) = 0;//右边的置位1 j = j + 1; } } } fwrite(&fileHead, sizeof(BITMAPFILEHEADER), 1, fop); fwrite(&infoHead, sizeof(BITMAPINFOHEADER), 1, fop); fwrite(pColorTable, sizeof(RGBQUAD), 255, fop); fwrite(pBmpBuf2, lineByte*height, 1, fop); fclose(fop); system("pause"); return 0;} 实验结果:Thank you for reading this article carefully. I hope the article "how to achieve BMP Image closed processing in C language" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.