In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use C language to achieve BMP image open operation processing". In daily operation, I believe that many people have doubts about how to use C language to achieve BMP image open operation processing. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for everyone to answer the doubt of "how to use C language to achieve BMP image open operation processing". Next, please follow the editor to study!
The open 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. Filter out the spines smaller than the structural elements, cut off the slender lap and play a separation role.
Operation: to open A with B is to select some points in A that match B, which can be obtained by the translation of the structural element B completely contained in A. That is, corrosion and then expansion.
# 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 ("open.bmp", "wb"); if (fop = = 0) return 0; / / define structural element / / etching operation int t = 0, d = 0, r = 0; 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){ *(pBmpBuf + (i - 1)*lineByte + j) = 0;//下边的置位1 } if (t == 0 && r != 0){ *(pBmpBuf + i*lineByte + j + 1) = 0;//右边的置位1 j = j + 1; } } } // 膨胀操作 // 初始化 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; // 当前点 } } 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;} 实验结果:Analysis of the experimental results: there is little difference between the effect picture and the original image. But details such as eyes are slightly different.
At this point, the study on "how to use C language to achieve BMP image open operation processing" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.