VittorioAccomazzi / LeafSize

🍃 Leaf and Pathogen quantification
0 stars 0 forks source link

Investigate images with black background #14

Closed VittorioAccomazzi closed 1 year ago

VittorioAccomazzi commented 1 year ago

Images with black background allows to visually see the lesion and leaf better than images with white background. These are typically taken for publication. Investigate if they can also be used in the application.

VittorioAccomazzi commented 1 year ago

Sample Data

Using the following two images (click to view full resolution): I was able to process without any modification to the application correctly as follow:

processed with version 56f990a
VittorioAccomazzi commented 1 year ago

Leaf identification

The leaf identification is done thresholding the Hue (H) and Saturation (S) component in HSV colour space and then performing morphology operations.

The Hue, Saturation and Value components of images with black and white background are the following:

Input Image Hue Saturation Value

From the table is visible that only the Value component has a different contrast (with the white background the leaf is darker with the black background the leaf is brighter). However this component is not being used in the identification process and therefore no changes are required, the current implementation shall be working . This explained the result obtained above.

It is also worth noticing that the contrast (as absolute difference between leaf and background) is comparable in both type of images : the hue has more contrast in images with black background ( 170 vs 90) and the saturation in images with white background (200 vs 130).

However in the Saturation component of the images of the black background there are areas in which the lesion is at the border of the leaf, and since the lesion is dark the contrast with the background is not as good as in the images with white background: 208214240-ba262d98-b20e-4993-84e7-7964ba0ffe18

VittorioAccomazzi commented 1 year ago

Lesion Identification

The lesion identification uses the A and B component of the LAB colour space for thresholding and then then performing morphology operations.

Input Image L A B

In this case we are interested on the contrast between the pathology region and the leaf and the colour of the background has little to do about it. Therefore the two images are equivalent from an image processing standpoint.

VittorioAccomazzi commented 1 year ago

Processing Image with White and Black Background

The application shall be able to process images with black background as well as images with white background. Images with black background might have little contract in the area where the lesion extends up to the boundary of the leaf, and so meets the background. Beside that images with black backgrounds and white backgrounds are equivalents.

As a matter of fact I can process in the same batch images with both backgrounds: image

VittorioAccomazzi commented 1 year ago

Image with Mixed Background

I just received images as the following one, in which the background has some black areas and white areas (such as the ruler): bb The image decomposition is the following:

L A B
Hue Saturation Value

As per analysis above the L and Value components are not used in the process, and these are the ones which are not working for the algorithm since the intensities of the leaf are in between the ones of the black background and white ruler.

The system indeed seems to perform quite well on these images with minor changes on the default values. With this settings I obtained the following result (click to magnify):

Screen Shot 2022-12-23 at 4 42 33 PM

Inaccuracies Analysis

There are however some inaccuracies in the leaf identification and specifically in one image some area of the background are included in the leaf, as shown below. Looking at the values it seems difficult to eliminate this area using thresholding because the Hue value is 28 well below the current threshold of 70 and the saturation value 149 well above the current threshold of 69. So changing any these threshold will have huge impact on the rest of the image (click to magnify):

Screen Shot 2022-12-23 at 5 01 19 PM

When looking at the hue and saturation images of this leaf, it is visible the anomaly in this area, I due to the fact that black in HSV can be represented in many ways ( with any value for H and S and zero for V as shown in this picture). This is a numerical instability.

Hue Saturation
!
VittorioAccomazzi commented 1 year ago

Conclusion

The images with black background are mostly equivalent with the images with white background, and from the application standpoint the two set of images are equivalent. However they seems to have 2 minor drawbacks:

One possible solution in order to present images with dark background, is to acquire them with white background and then digitally dark the background in order to: