For now, due to its convenience and simplicity, I use Python to design the algorithm and find the solution to this program. What I have done:
- Read dicom images.
- Extracte the data in the dicom files, such as pixel, rescale slope and rescale intercept.
- Use the extracted data to calculate CT value by the formula:
Hu = pixel * rescale slope + rescale intercept
- Scale the value of pixel data into 0~255, so that we can apply image processing algorithms to this gray image.
- Now we have two matrices. One is CT value matrix. The other is image matrix.
Now, we use the image matrix. First, we find the inner circle of the rock container to fliter out the rock container when calculating porosity later. Then, by findContours algorithm, we know where is the target. Program flow:
- make the image blur
- use Canny algorithms to find the edge of the image
- find the inner circle of the rock container by Circle Hough Transform
- Threshold the image to create a binary image
- apply findContours algorithm.
First of all, use the CT value matrix as reference. If the point in the image matrix is in the circle and the contour of the target, we push the CT value into an array for further calculation. Second, after viewing all point, grab the max value in that array, which is CTG. So, we have CTG and the CT value of the target. Last but not the least, applying the formula (CTG - Hu) / CTG, suming them up and dividing by the number of pixel in the target, we get the porosity of the rock.
- get CT value of the point inside in circle and contour of the target.
- get the CTG value
- apply the formula (CTG - Hu) / CTG
- sum them up
- divide by the number of pixel in the target
It's all because we want to remove the CT value of the container. It will have a big error if we only use findContours algorithm since when we find the contour of the target, we also include the container. To avoid this situation, we filter out most of container by Circle Hough Transform.
- The efficiency of the whole alogrithm is bad. It take a few second to calculate the porosity of a photo, which I think is unacceptable if we need to calculate all of x-ray image of core sample in the future.
- There are some errors we can minimize. One is the CT value of outter cover that protect the core sample, in fact, should be cut out. Another is that if we could know how many pixels of the container are, we can completely filter it out by some math formulas.x`
- testCircle -> calculate the Porosity,
- testCircle_reverseColor -> turn x-ray pictures to 3d along with 3d slider(for building 3d) and blander(for better viewing)
- config.json
- 最大 porosity 是用 F 點算出來的。最小是用 E 點算出來的 https://www.geogebra.org/calculator/dsfm3pdx
python ./GenerateCubesFromLabels.py '../dcmCutCycleOut_copy' 0 300 2
python ./GenerateCubesFromLabels.py '../dcmCutCycleOut_copy' 0 5000 2
python ./readDicomCntCT_findInnerCircle_findPorosityByVTK.py './dcmCutCycleOut_copy/'
python ./readDicomCntCT_findInnerCircle_findPorosityByVTK.py './dcmCutCycleOut_copy/' --isDraw
python ./readDicom_pickCenter3d.py './bh-3 DICOM-20230421T075124Z-001/bh3 15 dicom_20' --isDraw -outDirname './testDcmOut'
python ./readDicom_pickCenter3d.py './bh-3 DICOM-20230421T075124Z-001/bh3 15 dicom_20' -outDirname './testDcmOut'
- CNN is not good.