matthewb96 / FibreLengthAnalysis

Masters project to analyse the fibre lengths for glass fibres in a composite. This is done using a computer controlled microscope to take the images and image analysis tools to calculate the lengths.
0 stars 0 forks source link

Analysis of Crossing Fibres #5

Open matthewb96 opened 6 years ago

matthewb96 commented 6 years ago

The program needs to be edited so it can correctly analyse crossing fibres and does not find extra corners at crossing points, ideas to solve this:

Edited 19/02/18: Strikethrough the tasks that have been completed.

matthewb96 commented 6 years ago

As discussed in a comment in issue 3 there were more incorrect fibres found when more fibres were crossing, so some fixes need to be added to reduces the errors when analysing crossing fibres. This image shows the found fibres on a randomly generated image of size 1000*1000.

generated random image 2018-02-18_17-11-43 random image 1 drawn lines

This shows three major issues with analysing fibres, firstly corners are found at the intersections of fibres, secondly the lengths.checkLine() function is not correctly rejecting two corners that do not fully connect and finally some midpoints are found that are not part of a fibre (not shown in above image but seen in other tests). Commit b388da6e16fc81d899d1aa3b6340eb45f510a5fc addresses all three of these issues.

Firstly corners.findCorners() was edited so that the centroid position found is rejcted if it is not on a black pixel (i.e. part of a fibre), this removes the corners found at fibre intersections as the centroid position is on the inside of the corner, which is in white space at these intersections. These two images show where corners were found before and after this fix (red is centroid position, green in subpixel corner position and cyan is midpoint position). Before fix corners before fix After fix corners after fix

This removed the corners and midpoints at the intersections of fibres, also removing the corner on the short fibre where it just connects to the other fibre. This is how the found fibres look after this fix.

original random image 2018-02-18_17-32-54 drawn lines

This finds more of the fibres correctly but still finds fibres between two edges that are not connected, the reason for this was because in corners.checkLine() when finding midpoints the if statement was correct if the line had one midpoint on the fibres this meant that only half the line was checked, an and statement was added to change this.

image

The found fibres after change are shown below.

original random image 2018-02-18_18-09-36 drawn lines

This shows that still not all fibres are found due to some corners being missing when the corner of a fibre is within another fibre, but there are no false positive fibres found. Also as well as these two fixes when finding the midpoint of two corners to find the endpoint of a fibre that position was checked to be within one pixel of a fibre so that there were no endpoints found between two separate images, this was not a problem in the image used for testing but has been seen in other images.

matthewb96 commented 6 years ago

Tested the new code with some random images (commit 8a8659e140ac4d2ef47ad9687bb94a11b8558dd5) and found that some of the corners were not being found, when turning on debugging it was seen that some of the corners were being removed during thresholding. In order to fix this the thresholding value was lowered to 0.5*max instead of 0.7*max.

Then some real data was tested (commit cdc2be9689f7e0739ced00df8d2865550b09cd80), the image was thresholded directly after opening to make analysis easier. When analysing these images the program only found one corner at each edge, instead of two, this meant midpoints could not be found. Need to take some greater magnification images and see how they are, or possibly change the code to consider corners to be endpoints if two per edge cannot be found.

matthewb96 commented 6 years ago

Reverted the above fixes to test the code for each fix and see the graphs produced (commits 174e0a275e882cb89f904c9e8d3893a99a009c87, 60c043535e60b76855faedc00a0b0e86fd780046, 7f554dc78bad6ab3e2e40d7be01ef9b83260ec52 and d4e971a8650144790fc0c679d4fecc158ffd2216). Graphs containing the incorrect, correct and one away data were created as well as a new function being written to create graphs showing the percentage of fibres that are incorrect (commit a65e9eb2d4a8709680f3f5eec8f162613c960a59). Here are all the graphs showing percentage data.

An exponetial fit has been fitted to the percentage graphs to show the decrease in incorrect fibres as the array size increases, with a straight line at 1% to show the percentile error. By looking at these curves you can see how the 3 fixes that were done have reduced the percentage of incorrect fibres in the analysis. Error bars should be added to these curves to give a better understanding of the data.

matthewb96 commented 6 years ago

Edited the midpoint finding (commit 954ec7f404f7a61b2b8bde0efc88734a408f60c0) so that if a midpoint for a corner could not be found because only one corner on an edge was found then the corner would be added to the midpoints array and used as a midpoint, this allows for fibres to be found if not all four corners have been found but at least two have been (one at either end). This correctly found more fibres, although there will be an error in fibres where the length was found between opposite corners. x20_transmission6 2018-02-27_17-55-21 drawn lines

It is still seen that some fibres are not found so lengths.checkLine() was edited to check one of the surrounding pixels is part of a fibre, this means that the program would still known it was on a fibre if it was along one of the edges. Also reduced the MIN_LENGTH variables to find smaller fibres (commit 5c7fbe8b78b918bf18ff4ad83398c2e6f70494e0). Image showing the results of this change, same analysed image as above. x20_transmission6 2018-02-27_18-32-25 drawn lines

matthewb96 commented 6 years ago

Re-organised the code in main.py to move all the code for analysing a single image into a separate function analyseImage() (commit 0d2a539b3cd0f8e2441b6eb87f5f69c13d29806e). Then, in commit 5d7eea59fd28fe52ef92c4c4734695a9ce381079, functionality for analysing multiple images or a whole directory within one run of the program was added to make analysing a lot of separate images able to be done just by typing the filenames with spaces into the input field, or by typing "Dir directory name". This relied on filenames and directory names containing no spaces. Finally, in commit 8749d951841699b60687dcd3a7227b6734d72375, functionality was added to analyse multiple random images with different variables by simply typing "Random 1 10 1000 1 10 2000". This would analyse two random images the first with 1 loop, 10 fibres generated and an array size of 1000 and the second with 1 loop, 10 fibres generated and an array size of 2000. This made testing with random images much easier as not as much input was needed.

matthewb96 commented 6 years ago

Commit fc18b4ceae3679e83bd28de34e8bebff21535287 edited inputs.openImage() to remove small objects from the image before returning it, also all images could be seen in debugging mode. This was done using remove_small_holes() from the morphology module in skimage. Here is an example. x20_transmission1 2018-03-04_16-18-50 x20_transmission1 2018-03-04_16-18-50 drawn lines This works well on real data however when analysing images with different magnifications you need to make sure to update the FIBRE_WIDTH and MIN_LENGTH variables.

matthewb96 commented 6 years ago

Finally some tests on real data were done to see how well the program was analysing the fibre images and how the length distributions look. The below image shows the length distribution from analysing all of the images collected on 22nd February, this included images of both transmission and reflection and of varying magnifications (x10, x20 and x50). It was done as a simple test but different magnification images should not be anlysed together as the two variables FIBRE_WIDTH and MIN_LENGTH vary based on magnification. x50_transmission7 2018-03-04_16-11-10 length distribution of the found fibres for the total data Here is a length distribution of just the x20 transmission images collected on the same day. x20_transmission6 2018-03-04_16-18-50 length distribution of the found fibres for the total data

Both images show the expected distribution skewed to lower lengths, and when looking at the images x20 transmission seems to be the most accurate magnification in terms of correctly finding the most fibres. This is just seen by eye when looking at the images though. More x20 transmission images will need to be taken so analysis can be done on a larger number of images.