Towardsai 2024年06月03日
The Brief History of Binary Images
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Last Updated on June 3, 2024 by Editorial Team Author(s): Radmila M. Originally published on Towards AI. Photo by Etienne Steenkamp on Unsplash Introduction Binary images might be called as the simplest form of images that can take on two values — black and white, or 0 and 1. Basically, a binary image is a 1-bit image because it takes only 1 binary digit to represent each pixel in it. While binary images may lack the detail found in grayscale or color images, but they are still incredibly effective at isolating objects and shapes within an image and are widely used in many scientific fields, e.g. in applications where the only information required is general shape or outline, for example optical character recognition, as well as in computer vision problems, in medicine and the oil industry, to name a few. The simplest (and perhaps a little bit ‘zoomed in’) example of such a black-and-white image is a chessboard, though it is not a binary one. Here we also have only black and white squares, which can be considered as ‘pixels’. This analog will help to understand the mechanism of calculating the ratio of white pixels over the sum of both black and white ones, which will be called ‘porosity’ in the case of a binary image of rocks — more information about this concept will be given later. Photo by Joshua Hoehne on Unsplash By the way, QR codes that are widely used in e-commerce in order to scan them and find out more information about goods and zebras that you can see on the cover image are other examples of black-and-white objects ? In this post, I will guide you through the comprehensive procedure of working with binary images using Python, in particular with PoreSpy [1, 2], which is a collection of image analysis tools used to extract information from 3D images of porous materials, typically obtained from X-ray tomography, and DeePore [3], a deep learning workflow for rapid estimation of a wide range of porous material properties based on the binarized micro-CT images. Below I will consider 3 general cases of working with binary images in terms of image analysis, which involves the extraction of measurements from an image. Here and below, we will use a 3D micro-CT model of the Berea sandstone from the open database of the Imperial College London [4]: One of the slice from the 3D sample of Berea sandstone. Image by Author. Use Cases for Working with Binary Images in Python Case 1: Calculating porosity One of the most significant properties that can be determined during image analysis is the porosity or one-point correlation function from the statistical point of view. But what is porosity from the physical point of view? The texture of rocks consists of mineral grains with different shapes and sizes, therefore their pore structure is extremely complex. The most important factors of the pore structure are how much space there is between these grains and what their shapes are. Because of that, porosity is one of the most important rock properties; it can be defined as a measure of space between grains available for storage of different liquids or gases, for instance, water and hydrocarbons. Quantitatively, porosity is the ratio of the pore volume to the total bulk volume. It is possible to calculate porosity using Python. First, we need to read 3D image given in a .raw format as a numpy array. After that, all black pixels can be calculated. Next, white pixels can be found as the difference between im.size and black pixels. Finally, porosity, or the ratio of white pixels which are related to spaces between grains over the sum of white and black pixels (keep in mind, the latter are associated with grains). import numpy as np#3D imagefile_name = 'Berea.raw'voxel_size = 400dimension = 400shape = [voxel_size, voxel_size, dimension]im0 = np.fromfile(file_name, dtype = 'bool', sep='')im = im0.reshape(shape)#print(im)# Finding porosity, i.e. the ratio of white pixels over the sum of black and white onesblack_pix = np.count_nonzero(im)print('Number of black pixels:', black_pix)white_pix = im.size - black_pixprint('Number of white pixels:', white_pix)porosity = white_pix /(white_pix + black_pix)print('Porosity:', "%.4f"% porosity) When running this code snippet, one will get that the value of porosity for the considered Berea sandstone micro-CT image is equal to 19.6% (0.196), which coincides with the value stated in the output file on the Imperial College London’s website. The whole output of the above code looks as follows: Number of black pixels: 51427006Number of white pixels: 12572994Porosity: 0.196 By the way, it is possible to plot porosity profiles across three main axes within the given 3D image to see how this parameter varies inside the sample. In this case, the code should include the following lines (here im was defined as im0.reshape in the previous code fragment): import porespy as psimport matplotlib.pyplot as pltprf0 = ps.metrics.porosity_profile(im, axis=0)prf1 = ps.metrics.porosity_profile(im, axis=1)prf2 = ps.metrics.porosity_profile(im, axis=2)plt.plot(prf0, 'b.-')plt.plot(prf1, 'g.-')plt.plot(prf2, 'm.-')plt.plot([0, 400], [0.804, 0.804], 'r--')plt.ylim([0, 1])plt.xlabel('Distance, pixels')plt.show() Porosity profiles of the studied Berea sandstone image. Image by Author. As it can be seen, there is no strong porosity fluctuations for all directions within the sample — all curves lie near the red line with the value of 0.804 (i.e. 1 — porosity = 1–0.196). This observation correlates with a known fact that the Berea sandstone is a well-sorted and homogeneous rock. Case 2: Plotting the two-point correlation function As it can be seen from the previous case, porosity might be interpreted as a one-point probability function for a void phase (or pores), and it reflects the probability of the chosen point to be inside the considered phase. Another important characteristic of any binary image is a two-point correlation function, which can be interpreted as the probability of finding two points separated by some distance within the same phase (pores or grains). This two-point correlation function is typically used to investigate the sample’s heterogeneity since it contains important information about the typical feature size of image objects and depends on both rock particles and […]

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

相关文章