Introduction

Mushrooms gain huge popularity worldwide because of the various advantages associated with like low calories, lower level of sodium, fat (2–3%) and cholesterol, making it a functional food, and it is also rich in protein (27–30%), carbohydrate (45–48%), fibre (11–13%), vitamins and essential amino acids (Dibaba and Abera 2017; Li et al. 2021). It is cultivated on large scale around the world (as it can be cultivated in different climatic conditions), hence easily available (Li et al. 2021). Continuous demand for agricultural products with higher nutritional quality is one of the challenges to meet the increasing food requirement of the world population. Mushroom may be a solution to meet the future food requirement. In comparison to other vegetables, mushrooms have a short shelf-life period of 3–4 days (Kumar et al. 2021). This is because unlike other vegetables, there is no cuticle in them which could protect them from any physical harm or microbial deterioration or water loss (Aguirre et al. 2009). Pathogenic bacteria and fungus can cause blemishes to the body; discolouration is very common in them due to bruising and storage period (Aguirre et al. 2009). High water activity and high respiration rate make them susceptible to microbial spoilage. Enzymatic browning is also seen in them because of high tyrosinase and phenolic content. As a result of microbial changes and browning reaction, the white colour of fresh mushroom turns brown (Aguirre et al. 2009). A wide range of product variations is the most crucial part of mushroom production. There is a huge variation in product with different stages of maturity, which cannot be maintained easily; hence, to control this, a monitoring system may be useful in this regard.

The consumer-driven vegetable market is facing a continuous increase in requirement for higher value with respect to the mushroom product quality (Li et al. 2021). The cutting-edge researches indicate adverse health issues are related to consumption of spoiled mushroom (Adebo et al. 2021). Thus, reliable scientific methods for on-site mushroom quality evaluation are a need in recent days (Przybylak et al. 2016). The conventional fruit quality evaluation is generally offline and destructive in nature. Therefore, a rapid, non-invasive, non-contact, diverse, eco-friendly and precise system is to be developed for mushroom quality assessment (Suktanarak and Teerachaichayut 2017; Caballero et al. 2017). Digital image analysis has been used to assess the quality of agricultural produce due to its proven features like non-destructive, rapid, cost-effective and accuracy (Ma et al. 2016; Hussain et al. 2018). Though the freshness of food materials is prospective, it regulates the consumer preference most. Freshness depends on the variety of the fruit, and on the experience of the evaluator (Koyama et al. 2021). Objective indices and consumer evaluation has been combined to follow the freshness concept in terms of consumer perception (Koyama et al. 2021). Quantifiable standards like colour, texture and shape perform as a critical indicator during interpretation of sensory evaluation. On contrary, physicochemical characteristics could not reflect the perception of the consumers directly. Freshness prediction with sensory evaluation based on a traditional panel-based system is expensive, time-consuming and skill-dependent whereas machine-learning-based techniques may have higher efficiency. The classification is possibly similar to human sensory assessment without the intervention of a panellist once the model is built with an adequate dataset. The quality of puffed snack (Sanahuja et al. 2018), fish (Dowlati et al. 2013; Liu et al. 2015) and olive oil (Angerosa et al. 1996) has already been evaluated with machine learning. Texture profile, sound-based sensors and image processing have been considered to construct the predictive models. To evaluate the freshness of fruit, visual perception has been considered most important (Péneau et al. 2007; Wada et al. 2007). Machine learning and digital image processing are in practice to facilitate food quality prediction. Smartphone-based digital image processing in combination with machine learning has been used in the freshness classification of squid and fish samples (Navotas et al. 2018; Hu et al. 2020).

In the case of agricultural production, one of the most crucial steps is the sorting of products. It is extremely important to sort the defective products from the superior quality ones. If there is a huge variety in products, then sorting becomes a laborious and tough job. It is seen in fresh agricultural products as various factors like cultivation environment, nutrition, planting mode affect the sorting process (Bhargava and Bansal 2020a). Grading of products during the postharvest period is essential for mushrooms. The huge workload leads to chances of less accurate grading which will ultimately affect the economic aspects in the case of manual grading. Instead of manual grading, the automatic sorting system method offers various advantages like their high speed, non-destructive evaluation and higher production capacity (Wang et al. 2018).

The covariance analysis followed by the associated eigenvalues and eigenvectors be possible with principal component analysis (PCA). Several principal directions are obtained from which the principal components (PC) with a decreasing importance order are achieved. The essential feature to identify a digital image or to reduce the dimensionality of multivariate data, PCA has been used efficiently. Defect is detected in peaches (Sun et al. 2018), apple (Bhargava and Bansal 2021) and tomatoes (Machado et al. 2020).

Biological processes have been modelled reliably and efficiently with the artificial neural network (ANN) for the evaluation of specific objectives (Gago et al. 2010). The arrangement and functioning of the human neural system are simulated in ANN for processing input information followed by decision-making. The non-linear and complex biological events could be modelled with ANN due to its inherent learning mechanism to establish the relationship between input and output features (Gago et al. 2010; Dutta Gupta and Pattanayak 2017). Internal browning of mango (Gabriëls et al. 2020), quality assessment of spray-dried powdered juice of rhubarb (Przybył et al. 2020) and chlorophyll content in apple (Pourdarbani et al. 2020), banana and avocado (Bhargava and Bansal 2020b), gradation of mulberry fruit (Azarmdel et al. 2020), detection of defective lemons (Jahanbakhshi et al. 2020) and mass estimation of Ziziphus mauritiana have been evaluated with ANN aided image analysis. Table 1 shows a comparative analysis of several research works.

Table 1 Performance analysis of different research methods

Methodology of Sample Preparation

Oyster Mushroom Sample Collection

White oyster mushrooms (Pleurotus florida) were purchased from HACCP-certified and FSSAI-registered co-operative society of Kolkata, West Bengal, India. The samples were plucked at the time of procurement. The samples were fresh and white coloured, containing 85–87% of moisture. Emphasis has been given on reducing the time gap between purchases of the mushrooms and bringing them to the laboratory (it has been set within 15 min). Room temp has been maintained at 25 ± 5 °C, with a relative humidity of 80 ± 5%. They were not exposed to direct sunlight and no other preservatives have been used so that natural decomposition can be observed.

Image Acquisition

To study the decomposition rate, pictures were captured from the very first day using Redmi Note 9 Pro (specifications: with 8-nm processor, 4-GB RAM, 128-GB memory, 48–megapixel camera, android system, and Samsung Isocell GM2 sensor) taking view from all angles. Four LED lights were installed in the room (Eveready 20-W LED Batten, 20 W, 113.5 × 2.5 × 3.6 cm, luminous flux of 100 lm/W Lumen, colour temperature of 6000 K) to make sure there is proper lighting facility to capture images. Mushrooms were placed at an average distance of 20 cm from the smartphone to take images.

Evaluation of Quality Classes of the Mushrooms

The sensory qualities of the mushrooms were judged by a group of a semi-trained panel which consisted of 39 females and 30 male persons between the age group 21 and 45 years. ISO 8586–1 (1993) was followed in performing this. On the other hand, ISO 5496:2005 and ISO 10399:2004 were employed respectively to identify the colour and texture to distinguish two different mushrooms (Mukherjee et al. 20212022; Sarkar et al. 2021). Whether the sample falls under good or bad class is determined by three specific sensory attributes namely shape, colour and texture. Figure 1 is a visual representation of the quality classes of the mushrooms with representative samples both from the fresh (Fig. 1(a–e)) and the deteriorated classes (Fig. 1(f–i)).

Fig. 1
figure 1

Raw images of the Oyster mushrooms (Pleurotus florida) samples (ae) fresh class and (fj) deteriorated class

Preprocessing of Mushroom Images

The mushroom samples are pre-processed minimally with cropping the centre part of it. This allows accommodating the maximum surface of mushroom in the cropped image. We have further resized each image to 300 × 300 dimensions. This provides uniformity to each image sample for analyzing with the proposed freshness classifiers.

Feature Extraction from Mushroom Images

We have investigated ten major colour features of the mushroom samples and one major texture feature in this work and developed a freshness detection algorithm using two different methodologies employing PCA and ANN independently. Apart from that, we have further analyzed five minor features of each of the colourmap layers and four specific greyscale image features using the ANN classifier only. These are described as follows:

Major Features

Here, we have analyzed three major colourmaps of the mushroom sample images. These include red (R)-green (G)-blue (B) colourmap, hue (H)-saturation (S)-value components (V) colourmap and luminance (Y)-chrominance (Cb and Cr) colourmap. Each of these colour spaces contains 3 layers independently. The RGB layer is the default colourmap of the images, which are obtained just by separating the three independent layers. Each layer is analyzed to develop intensity histograms, with pixel intensity levels varying in the range from 0 to 255. The RGB colourmap is later transformed to HSV and YCbCr colourmap, from which the histograms of each of the H, S and V layers, as well as Y, Cb and Cr layers are extracted. Finally, the images are converted to greyscale form, from which the greyscale histogram is obtained. Each of these histograms is used as the key major features of analysis in the proposed work and, hence, used to develop the freshness assessment algorithms. Each colourmap is discussed in detail in the subsequent sub-sections.

Red (R)-Green (G)-Blue (B) Colourmap Features

The R, G and B layers are the layers of the default RGB colourmap of the images. These are altogether denoted as a colour histogram. Minor changes in the tiny off-axis, observation axis, sometimes rotation of the image, or even small occlusion in the camera lens do not majorly affect these features. Hence, these RGB features are considered some of the most significant and useful features. This is especially important for the classifiers, which use smartphone camera-based image capturing method of the food samples due to the unavoidable difference in the smartphone camera specifications and the captured image quality. The histograms of the RGB colourmap are developed in bunches, using the number of required bins as follows:

$${\mathrm{Bin}}_{a} \left(\mathrm{R},\mathrm{ G},\mathrm{ B}\right)=[\left({f}_{\mathrm{R}1},{f}_{\mathrm{R}2}, \dots ,{f}_{\mathrm{Ra}}\right)\left({f}_{\mathrm{G}1},{f}_{\mathrm{G}2},{\dots f}_{\mathrm{Ga}}\right)({f}_{\mathrm{B}1},{f}_{\mathrm{B}2},\dots {f}_{\mathrm{Ba}})]$$

Here, the range of intensity values are segmented into ‘a’ number bunches. Further decomposition is done to segregate the R, G and B layers. The histogram is thus developed as:

$$\mathrm{Histogram }{(H}_{i})=\frac{\mathrm{Number ofpixels in}{ H}_{i}}{\mathrm{Height}\times \mathrm{Width}}$$
(1)

where i is one of the layers amongst R, G or B.

Hue-Saturation-Value Component Colourmap Features

The most important use of the HSV colourmap is that it separates ‘luma’ or the light intensity of the image from ‘chroma’, which is the colour information of the same. That helps in histogram equalization. Hence, these features are extremely insensitive against variation in lighting conditions, thus, helping in developing robust classifiers, especially considering all weather conditions where the natural light varies, or the variation in artificial lighting or flashlight exists. Most importantly, these features help immensely in developing smartphone-based image processing algorithms, disregarding the ambient lightings or the inbuilt flash. These features are represented as follows:

$$H =\left\{\begin{array}{c}\theta B\le G\\ 360^\circ -\theta B\ge G\end{array}\right\}$$
(2)
$$\mathrm{where} \theta = {\mathrm{cos}}^{-1}[\sqrt{\frac{\left(R-G\right)+(R-B)}{{(R-G)}^{2}+\left(R-B\right){(G-B)}^{1/2}}}]$$
(3)
$$S=1-\frac{3}{R+G+B}$$
(4)

where R, G and B represent the red (R), green (G) and blue (B) layers.

Luminance-Chrominance Colourmap Features

The luminance can be separated effectively from the chrominance with the help of the YCbCr colour channel. The extent of light in the entire spectrum of the image is described by luminance. The colour information of a digital image in terms of cyan blue and cyan red is conveyed through Cb and Cr respectively (Binti Zaidi et al. 2015).

$$\left[\begin{array}{c}Y\\ Cb\\ Cr\end{array}\right]=\left[\begin{array}{c}R\\ G\\ B\end{array}\right]\left[\begin{array}{ccc}0.257& 0.504& 0.098\\ - 0.148& -0.291& 0.439\\ 0.439& -0.3678& -0.0714\end{array}\right]+ \left[\begin{array}{c}16\\ 128\\ 128\end{array}\right]$$
(5)

Minor Features

Apart from these major features, five other minor or secondary features of each layer of the RBG, HSV and YCbCr colourmap and the greyscale image are analyzed using the proposed ANN freshness detector. These features are mean, standard deviation (SD), entropy, kurtosis and skewness. Apart from these, four other minor features, namely, contrast, correlation, energy and homogeneity are also extracted using the grey-level co-occurrence matrix (GLCM) of the greyscale image. A detailed discussion of some of these features is done in the following sections.

Mean

The mean of each layer is computed by computing the average or mean of matrix elements of the corresponding layer. Here, mean is computed for each layer image of the RGB, HSV and YCbCr colourmap, which are individual images, hence, matrices.

$$\mathrm{Mean }=\mathrm{ average of }(\mathrm{matrix elements of the image layer}) =\frac{1}{{N}^{2}}{\sum }_{k=0}^{{N}^{2}-1}{P}_{k}$$
(6)

where \({P}_{k}\) is the pixel intensity of the N × N image corresponding to all layers independently.

Standard Deviation

The standard deviation (SD) of each layer is computed similarly by computing the standard deviation of matrix elements of the corresponding layer of the RGB, HSV and YCbCr colourmap. The generalized form of standard deviation is found as:

$${\mathrm{SD }= (\frac{1}{{N}^{2}}{\sum }_{k=0}^{{N}^{2}-1}{(P}_{k}{- \overline{P })}^{2})}^\frac{1}{2}$$
(7)

where \({P}_{k}\) is the pixel intensity of the N × N image corresponding to all layers independently and \(\overline{P }\) is the mean of the same.

Entropy

The entropy of an image is the representation of the statistical measure of randomness of the pixel intensity values. Thus, it characterizes the texture of an image very efficiently. The entropy of a layer of the image, which essentially becomes a grey-level image, is measured by:

$$\mathrm{Entropy }(\mathrm{En})=\sum\nolimits_{x=0}^{GL-1}{(\mathrm{Probability}}_{x}) {\mathrm{log}}_{B}({\mathrm{Probability}}_{x})$$
(8)

where GL is the grey-level number and Probabilityx is the probability of a pixel to have a GL value of x, and B is the base of the logarithm. The Probabilityx truly contains the histogram counts of each image.

Kurtosis

Kurtosis is a statistical parameter that measures the difference in the distribution of tails of any distribution from that of a normal distribution, for which the value of kurtosis is 3. In the distributions, where there are more outliers compared to the normal distribution, the yield kurtosis exceeds 3, and for the distributions where the number of outliers is less, it has kurtosis value less than 3. It is computed as below.

$$\mathrm{Kurtosis}\; (K)=\boldsymbol{ }\frac{1}{{\mathrm{SD}}^{4}} {E{(P}_{k}- \overline{P })}^{4}$$
(9)

where \(\overline{P }\) is the mean value of the pixel intensity variable P, SD is the standard deviation of P, and E(f(n)) denotes the expected value of the function f(n).

Skewness

Skewness is a parameter that measures the asymmetry of the probability distribution; also, it measures the extent by which any pixel is lighter or darker compared to the average level, i.e. the sample mean. A negative value of skewness denotes the distribution is shifted more towards the left of the mean level, and a positive value of skewness indicates the distribution is spread out or skewed more towards the right. mean level. Thus, it is obvious that the skewness of a perfectly symmetric distribution, which may be regarded as a normal distribution, is zero. The skewness is represented using the following equation:

$$\mathrm{Skewness }(S)=\boldsymbol{ }\frac{1}{{\mathrm{SD}}^{3}} {E{(P}_{k}- \overline{P })}^{3}$$
(10)

where \(\overline{P }\) is the mean value of the pixel intensity variable P, SD is the standard deviation of P, and E(f(n)) denotes the expected value of the function f(n).

Grey-Level Co-Occurrence Matrix Features

Grey-level co-occurrence matrix or GLCM is a statistical method that examines the texture of an image by considering the spatial relationship of the pixels. Hence, GLCM is also known as the grey-level spatial dependence matrix. The GLCM functions estimate the frequency at which pairs of the pixel with specific values and in a specified spatial relationship occur by inspecting the image; thereby, it creates a GLCM. Finally, statistical measures like contrast, correlation, energy and homogeneity are computed from this matrix. Thus, GLCM is essentially the computational characteristics of the probability density function or PDF of the grey-level matrix of any particular image. Thus, GLCM is given by:

$$\mathrm{GLCM}\left({p}_{1},{p}_{2}\right);{p}_{1},{p}_{2}=\mathrm{0,1},\mathrm{2,3},\dots \mathrm{P}-1$$
(11)

where P is the numbers of pixels in the image and p1 and p2 are the frequency value of pixel pair. The four GLCM features, as mentioned here, are computed as described in the subsequent sub-sections.

Contrast

Contrast essentially measures the local variations in the GLCM and it is estimated by the following expression:

$$\mathrm{Contrast}\; \left(C\right)= \sum\nolimits_{{p}_{1=0}}^{P-1}{\sum }_{{p}_{2=0}}^{P-1}{(\mathrm{GLCM} \left({p}_{1}{p}_{2}\right))}^{2}$$
(12)

Correlation

Correlation is a measure of the joint probability of occurrence of any particular pixel pair. This is generally used to measure the deformation, displacement, optical flow and strain in an image. Correlation is estimated using the following expression.

$$\mathrm{Correlation}\; \left(\mathrm{Corr}\right)=\sum\nolimits_{{p}_{1=0}}^{P-1}{\sum }_{{p}_{2=0}}^{P-1}\frac{{p}_{1}{p}_{2} GLCM \left({p}_{1}{p}_{2}\right)-({\overline{p} }_{1}{\overline{p} }_{2})}{{SD}_{1}^{2} \times {SD}_{2}^{2}}$$
(13)

where \({\overline{p} }_{1}{\mathrm{ and } \overline{p} }_{2}\) are the means and \({SD}_{1}^{2} \mathrm{and }{SD}_{2}^{2}\) are the standard deviation for p1 and p2 respectively.

Energy

Energy is estimated by computing the sum of squared elements in the GLCM. Energy also estimates the uniformity in an image or the angular second moment. The energy of an image is computed as follows:

$$\mathrm{Energy}\; \left(E\right)=\boldsymbol{ }\sum\nolimits_{{p}_{1=0}}^{P-1}{p}_{1}\sum\nolimits_{{p}_{2=0}}^{P-1}{({p}_{1}- {p}_{2})}^{2} \times \mathrm{GLCM}\; ({p}_{1}{p}_{2})$$
(14)

Homogeneity

Homogeneity (Ho) is a parameter that measures the closeness of the distribution of elements in the GLCM to the GLCM diagonal (transverse GLCM). Homogeneity is represented by the following expression.

$$\mathrm{Homogeneity} \left(Ho\right)= \sum\nolimits_{{p}_{1=0}}^{P-1}{p}_{1}\sum\nolimits_{{p}_{2=0}}^{P-1}\frac{\mathrm{GLCM} ({p}_{1}{p}_{2})}{1 + \mathrm{mod} ({p}_{1}{- p}_{2})}$$
(15)

Analysis Methods

In this work, we have developed two classifier models employing multivariate statistical methods like principal component analysis (PCA) and supervised learning model like artificial neural network (ANN) to develop the proposed freshness detection models using the oyster mushroom images. These methods are discussed in detail in the following sub-sections.

Application of Principal Component Analysis

Principal component analysis (PCA) is a statistical model which emphasizes the variance of a data set. The computation of the principal components is done in the following way (Jolliffe 2002). For a random variable x with y number of elements, PCA tries to develop a linear function C1x which would have the highest variation, expressed as:

$${{C}_{1}^{T}x= C}_{11}{x}_{1} + {C}_{12}{x}_{2 }+ \dots + {C}_{1y}{x}_{y}={\sum }_{j=1}^{y}\left({C}_{1j}{x}_{j}\right)$$
(16)

Similarly, another linear function CT2x is developed in such a way that it becomes uncorrelated with CT1x and it has a maximum variance. Similar uncorrelated linear functions such as CT1x, CT2x, , and CTm are continued until mth stage, and thereby obtain the mth principal component (PC). Practically, only a few PCs, up to nth PC, say, are considered for analysis, since these PCs carry major information in the decreasing sequence. Thus, the first PC is the most significant carrier of information, followed by the second PC, third PC etc. Thus, n is much less compared to m. This reduces the dimension of the data set largely. Most often, the unknown is substituted by the covariance matrix, denoted by Cov, and it is given by:

$$\mathrm{Cov}=\frac{1}{y-1}{X}^{T}X$$
(17)

Thus, the (j, k)th element of the same covariance matrix is given by:

$$\frac{1}{y-1}{\sum }_{i=1}^{y}{(\tilde{x }}_{ij}-{\overline{x} }_{j}){(\tilde{x }}_{ik}-{\overline{x} }_{k})$$
(18)

Now, if we consider \({C}_{1}^{T}{x}_{i}\) as \({\tilde{z }}_{i1}\), then the coefficients \({C}_{1}^{T}\) is chosen in such a way that it should maximize the variance given by the following expression.

$$\mathrm{variance}= \frac{1}{n-1}{\sum }_{i=1}^{n}{{(\tilde{z }}_{i1 }-{\overline{z} }_{1})}^{2}$$
(19)

It is obvious that \({C}_{1}^{T}{C}_{1}\) = 1 and \({C}_{1}^{T}x\), i.e. \({\tilde{z }}_{i1}\), is the first PC. Thus kth largest eigenvalue of the covariance matrix (Cov) is corresponding to the kth eigenvector \({C}_{k}\) corresponding to the kth largest eigenvalues \({\lambda }_{k}\), and the kth PC is found as \({z}_{k}\) which is the same as \({C}_{k}^{T}x\). Thus, \(\tilde{X }\) and \(\tilde{Z }\) are related with the expression as \(\tilde{Z } = \tilde{X }O\), where \(O\) is an orthogonal matrix. The kth column of this orthogonal matrix \(O\) is indicated by \({C}_{k}\).

As mentioned earlier that PCs are obtained by maximizing the variance, i.e. maximizing \({z}_{k}= {C}_{k}^{T}x= {C}_{k}^{T}\sum {C}_{k}\), governed by the constraint \({{C}_{k}^{T}C}_{k}=1\). Lagrange multipliers are used here as a standard method for maximizing the variance, i.e. by maximizing the function given by:

$$\left({C}_{k}^{T}\sum {C}_{k}\right)-\lambda ({C}_{k}^{T}{C}_{k}-1)$$
(20)

where λ is a Lagrange multiplier. On differentiation with respect to \({C}_{k}\), it yields:

$$\sum {C}_{k}-\lambda {C}_{k}=0, \mathrm{i}.\mathrm{e}.\left(\sum -\lambda I\right)C= 0$$
(21)

where \(I\) is an identity matrix. Using the above expression, we get independent sets of eigenvalues \(\lambda\) and the corresponding eigenvector \(C\) respectively. The highest eigenvalue \({\lambda }_{1}\) and the corresponding eigenvector \({C}_{1}\) are used to obtain the highest PC, which is given by \({C}_{1}^{T}x\). The subsequent PCs given by \({C}_{k}^{T}x\) are also obtained subsequently in a similar way. However, in this work, we have made use of only the first PC to develop the proposed PCA threshold–based freshness assessment algorithm.

Application of Artificial Neural Network

We have designed a three-layered artificial neural network (ANN) architecture for developing the freshness classifier model. The three layers correspond to the input layer, hidden layer and output layer, as is found in common ANN architectures (Ali and Dildar 2020). Histograms of each of the RGB, HSV, YCbCr, greyscale colourmap and the entropy-filtered image are given as input to the input layer of the proposed ANN architecture independently. The sigmoid activating function is employed in the proposed model, which is given as (Sarkar et al. 2020):

$${y}_{i}=\frac{1}{1+{exp}^{-(\sum \mathrm{input}+{\phi }_{i})}}$$
(22)

Here, input is given by \({{w}_{ki}\theta }_{k}\) and yi is the response of the ith node; ϕi is the bias at the same node; θk is the kth input to the input layer; and wki is the weight of the path corresponding to the kth input. Thus, the input layer response at the ith node of the hidden layer is given by modifying expression (19) as:

$${y}_{i}=\frac{1}{1+{\mathrm{exp}}^{-(\sum_{k=1}^{n}{{w}_{ki}\theta }_{i }+{\phi }_{i})}}$$
(23)

Similarly, the hidden layer output from the jth node (\({O}_{j})\) is obtained as:

$${{O}_{j}=\sum_{i=1}^{y}{w}_{ij}+ \phi }_{j}$$

where \({w}_{ij}\) represent the associated weight and \({\phi }_{j}\) is the predisposition of the jth node of the output (Tan et al. 2018).

Sample Segmentation

We have considered two sets of independent experimental data of the mushroom samples in this work. As mentioned earlier, it is observed that the mushroom samples remain Fresh during the first 3 days, and from the fourth day onwards, the samples deteriorate in quality, and the sample quality falls below level 6 on the Hedonic scale. Hence, the sample images from day 4 onwards are considered to be lying in the Deteriorate class of samples. In the first set of mushroom samples, we have accumulated 55 Fresh images, captured over the first 3 days, and a similar number for Deteriorate samples over the next 3 days has been 65. Hence, the set contains 55 and 65 sample images of the Fresh and Deteriorate classes respectively. Another set of samples has been examined with similar quality of mushrooms and finally, 65 and 55 numbers of sample images have been captured during the first 3 days and the following 3 days respectively. Thus, the number of samples belonging to the Fresh and Deteriorate class becomes 55 and 45 respectively. Thus, the total number of samples of these two classes finally become (55 + 65) i.e. 120, and (65 + 55) i.e. 120 respectively.

Samples Analyzed Using the Proposed Schemes

The first set of 55–65 samples has been used to develop the PCA threshold–based freshness detection algorithm. The second set of 65–55 similar mushroom samples has been used for testing the proposed scheme. Thus, this second set is used here to validate the proposed PCA threshold–based classifier.

But the ANN classifier has been analyzed in a minor different scheme. The whole sample set of 120–120 mushroom images are used to train, validate and test the proposed ANN freshness detection model with a 70:15:15 percentage ratio respectively; i.e. 70% or 84–84 number of samples are used to develop the training set; 18–18 number of samples are used to validate the model; another 18–18 number of samples are used for testing the same. Training has been carried out 10 times with each feature to obtain the best possible outcome, which is considered the final outcome of the model.

Result and Discussion

Analysis of Features

Two different classification models have been designed in this work using statistical analysis and supervised learning algorithms respectively. These models are analyzed separately using the 11 different major features and 54 other minor features of the mushroom samples. These major features include the histograms of the three independent layers of the red (R)-green (G)-blue (B) colourmap, hue (H)-saturation (S)-vital component (V) colourmap and luminance (Y)-chrominance (Cb and Cr) colourmap, greyscale image and texture map in the form of histograms of the entropy-filtered image. The minor features include mean, standard deviation (SD), entropy, kurtosis and skewness of each of the three layers of RGB, HSV and YCbCr colour space and the whole image itself, and the four vital greyscale image parameters like contrast, correlation, energy and homogeneity, obtained from the grey-level co-occurrence matrix (GLCM). These major features are analyzed using the PCA threshold model, and both the major and the minor features are analyzed using the proposed ANN-based freshness level classifier.

Three features from every three colourmaps are extracted from the image samples. The histograms of the red (R), green (G) and blue (B) layers are shown in Fig. 2 along with the scatter plot of the first and the second principal components (PC1 and PC2 respectively). Similar histograms and the PC scatter plot of the hue (H), saturation (S) and vital component (V) layers of the image samples are also shown in Fig. 3. Figure 4 shows the same for the luminance (Y) and chrominance colour values (Cb and Cr layers respectively). The histogram of the greyscale image (Gr) and entropy-filtered image (En), along with the corresponding principal component scatter diagram, is shown in Figs. 5 and Fig. 6 respectively. These histograms, as well as scatter plots, correspond to the first set of sample images which are used for developing the threshold-based PCA freshness detector.

Fig. 2
figure 2

Histogram and principal component scatter diagram of the RGB layers: a histogram of the red layer, b PC scatter plot of red layer histogram, c histogram of green layer, d PC scatter plot of green layer histogram, e histogram of blue layer, f PC scatter plot of blue layer histogram

Fig. 3
figure 3

Histogram and principal component scatter diagram of the HSV layers: a histogram of hue layer, b PC scatter plot of hue layer histogram, c histogram of saturation layer, d PC scatter plot of saturation layer histogram, e histogram of vital component layer, f PC scatter plot of vital component layer histogram

Fig. 4
figure 4

Histogram and principal component scatter diagram of the YCbCr layers: a histogram of Luminance (Y) layer, b PC scatter plot of luminance (Y) layer histogram, c histogram of chrominance 1 (Cb) layer, d PC scatter plot of chrominance 1 (Cb) layer histogram, e histogram of chrominance 2 (Cr) layer, f PC scatter plot of chrominance 2 (Cr) layer histogram

Fig. 5
figure 5

Histogram and principal component scatter diagram of the greyscale layers: a histogram of greyscale layer, b PC scatter plot of greyscale layer histogram

Fig. 6
figure 6

Histogram and principal component scatter diagram of the entropy-filtered image: a histogram of entropy-filtered image, b PC scatter plot of entropy-filtered image histogram

It was mentioned before that the samples begin to deteriorate from day 4 onwards, when the Hedonic scale suggests deterioration of fewer than 6 units. Hence, we have considered samples from days 1 to day 3 as Fresh, and those of days 4 to 6 as a Deteriorated class. It is well observed from Figs. 2, 3, 4, 5 and 6 that most of the scatter plots show major overlap between the two freshness classes: Fresh (day 1 to day 3) and Deteriorated (day 4 to day 6) classes. But, in the case with few features, the scatter plots show significant separation between the two classes, and hence, the possibility of developing a distinct threshold level using the PC1 value only. In all the cases, it is observed that PC1 values are significant enough to develop classification. Hence, only the first principal component has been used here for developing the PCA threshold–based classifier scheme. This further ensures reduced computation using only one PC direction.

Classifier Outcomes Using Major Features

Careful observation of Figs. 2, 3, 4, 5 and 6 shows that green, blue, hue, saturation, luminance and entropy image histograms and PC plots are better for developing a threshold level between the Fresh and Deteriorated classes, compared to the other major features. These PCA features are hence segmented using designed thresholds to test the same model with the second set of image samples. The test results of the PCA classifier are shown in Table 2 using the major features such as histograms of colour and greyscale colourmap, as well as the texture features in terms of the histogram of the entropy image.

Table 2 Comparative analysis of the outcomes of freshness class detection with major colour features using PCA threshold classifier and ANN classifier

As mentioned earlier, the first set contains 55 numbers of the Fresh class image and 65 numbers of the Deteriorated class of images. A similar count for the second set of images is 65 and 55 respectively. This altogether develops 120 numbers of Fresh and Deteriorated sample images. This full set of mushroom samples are used to train, validate and test the designed ANN classifier model in 70:15:15 ratio; i.e. 70% of the entire dataset are used to train the model, 15% of the samples are used to validate the same and the remaining 15% are used for testing the classifier. The same method is repeated using a random set of training-validation-test image samples to obtain the optimal level of accuracy, using each of the 11 major features, i.e. 10 different colour features and 1 texture feature. The test results obtained using the same is shown in Table 3, along with the results of the PCA threshold freshness model.

Table 3 Outcomes of freshness class detection with texture feature using ANN classifier

Analysis Using Minor Features

Five minor features of each layer of RGB, HSV and YCbCr colourmap are analyzed in this work apart from the 11 major features discussed in the earlier sub-section. These features are mean, standard deviation (SD), entropy, kurtosis and skewness of the layer pixel values. Besides, four other GLCM features, namely, contrast, correlation, energy and homogeneity, are also analyzed using the greyscale sample images. We have used boxplots to identify the significance and distinctness of separation of these minor features, in order to develop distinct classification between the Fresh and Deteriorated classes. These boxplots are shown for separate layers of each of the RGB, HSV and YCbCr colourmap. The boxplots of these minor features for the red, green and blue layers are shown in Fig. 7a, b and c respectively. Similar individual layer boxplots of the HSV and YCbCr colourmap are shown in Figs. 8 and 9 respectively. Figures 10 and 11 shows the five minor features of the original RGB image and the four GLCM features of the greyscale image respectively.

Fig. 7
figure 7

Distribution of minor features such as mean, standard deviation (SD), entropy, kurtosis and skewness of the a red layer, b green layer and c blue layer of the RGB colourmap for Fresh and Deteriorate classes of the mushroom samples

Fig. 8
figure 8

Distribution of minor features such as mean, standard deviation (SD), entropy, kurtosis and skewness of the a hue layer, b saturation layer and c vital component layer of the HSV colourmap for Fresh and Deteriorate classes of the mushroom samples

Fig. 9
figure 9

Distribution of minor features such as mean, standard deviation (SD), entropy, kurtosis and skewness of the a luminance layer, b chrominance 1 layer and c chrominance 2 layer of the YCbCr colourmap for Fresh and Deteriorate classes of the mushroom samples

Fig. 10
figure 10

Distribution of minor features such as mean, standard deviation (SD), entropy, kurtosis and skewness of the original RGB image for Fresh and Deteriorate classes of the mushroom samples

Fig. 11
figure 11

Distribution of GLCM features such as contrast, correlation, energy and homogeneity of the greyscale colourmap for Fresh and Deteriorate classes of the mushroom samples

Outcomes of the ANN Classifier Using Minor Features

Apparent observations of these boxplots show that some of the features exhibit significant separating of values between the two associated classes, whereas the other features do not show prominent significance. Hence, all these features are further analyzed only using the proposed ANN classifier model in a similar way as is done for the major features. The results so obtained are described in Table 4 and Table 5 to illustrate the classification accuracies.

Table 4 Outcomes of freshness class detection with minor features of the RGB, HSV and YCbCr colourmap using the proposed ANN classifier
Table 5 Outcomes of freshness class detection with GLCM features of the greyscale colourmap using the proposed ANN classifier

The proposed methods of analysis are described in the form of a flow diagram in Fig. 12.

Fig. 12
figure 12

Flow diagram of the proposed mushroom freshness classifier models

Performance Analysis

The performance of the model build is studied by considering the following equations.

$$\mathrm{Accuracy}\; \left(\%\right)=\left({P}_{\mathrm{T}}+{N}_{T}\right)/{P}_{T}+{P}_{F}+{N}_{T}+{N}_{F}$$
(24)
$$\mathrm{Precision}={P}_{\mathrm{T}}/\left({P}_{\mathrm{T}}+{P}_{\mathrm{F}}\right)$$
(25)
$$\mathrm{Sensitivity }\left({T}_{\mathrm{PR}}\mathrm{ or true positive rate}\right)={P}_{\mathrm{T}}/\left({P}_{\mathrm{T}}+{P}_{\mathrm{F}}\right)$$
(26)
$$\mathrm{Quality measure}=2\times \left(\mathrm{Sensitivity}\times \mathrm{Precision}\right)/\left(\mathrm{Sensitivity}+\mathrm{Precision}\right)$$
(27)
$$\mathrm{Intersection of overall union}={P}_{\mathrm{T}}/\left({P}_{T}+{P}_{F}+{N}_{F}\right)$$
(28)
$$\mathrm{Specificity }\left(\mathrm{true negative rate}\right)={N}_{\mathrm{T}}/\left({N}_{T}+{P}_{F}\right)$$
(29)
$$\mathrm{Negative predictive value}={N}_{\mathrm{T}}/\left({N}_{T}+{N}_{F}\right)$$
(30)
$$\mathrm{False}-\mathrm{positive rate}\left({F}_{\mathrm{PR}}\right)={P}_{\mathrm{F}}/\left({P}_{F}+{N}_{T}\right)$$
(31)
$$\mathrm{False}-\mathrm{negative rate }\left({F}_{\mathrm{NR}}\right)={N}_{\mathrm{F}}/\left({N}_{F}+{P}_{T}\right)$$
(32)
$$\mathrm{Mathew Correlation }\left(\mathrm{MC}\right)=\left[\left({P}_{\mathrm{T}}\times {N}_{\mathrm{T}}\right)-\left({P}_{\mathrm{F}}\times {N}_{\mathrm{F}}\right)\right]/{\left[\left({P}_{\mathrm{T}}+{P}_{\mathrm{F}}\right)\left({P}_{\mathrm{T}}+{N}_{\mathrm{F}}\right)\left({N}_{\mathrm{T}}+{P}_{\mathrm{F}}\right)\left({N}_{\mathrm{T}}+{N}_{\mathrm{F}}\right)\right]}^{1/2}$$
(33)
$$\mathrm{Kappa value}\; \left(K\right)=\frac{{A}_{0}- {A}_{e}}{1- {A}_{e}}$$
(34)

where

$$\begin{array}{c}{A}_{0}=\left({P}_{\mathrm{T}}+{N}_{\mathrm{T}}\right)/\left({P}_{\mathrm{T}}+{P}_{\mathrm{F}}+{N}_{\mathrm{T}}+{N}_{\mathrm{F}}\right)\\ {A}_{e}=\left[\left({P}_{\mathrm{T}}+{P}_{\mathrm{F}}\right)\times \left({P}_{\mathrm{T}}+{N}_{\mathrm{F}}\right)+\left({N}_{\mathrm{T}}+{N}_{\mathrm{F}}\right)\times \left({P}_{\mathrm{F}}+{N}_{\mathrm{T}}\right)\right]/{\left({P}_{\mathrm{T}}+{P}_{\mathrm{F}}+{N}_{\mathrm{T}}+{F}_{\mathrm{F}}\right)}^{2}\end{array}$$

where PT is the true positive, PF is the false positive, NF is the false negative, and NT is the true negative.

The performance analysis of the outcomes of both the PCA threshold–based model and the ANN model are shown in Table 6. Here we have examined only the features which produce classifier accuracy higher than 90%, as these features are considered the most important ones. Other features are not elaborated here since those yields less significant outcomes.

Table 6 Performance analysis of the obtained outcomes

Analysis of Results Using Major Features

It is observed that classification accuracy is higher in all the cases with ANN classifier, compared to PCA threshold freshness classifier. A comparative analysis of the outcomes of the two classifier models is shown in Fig. 13 which reveals the above fact more prominently.

Fig. 13
figure 13

Comparative analysis of PCA threshold and ANN classifier using different major colour and texture features: red (R), green (G), blue (B), hue (H), saturation (S), vital component (V), luminance (Y), chrominance 1 (Cb), chrominance 2 (Cr), greyscale image (Gr) and entropy-filtered image (En)

It is further observed that classifier accuracy exceeds 90% level for green, blue, hue, luminance and chrominance 2 (Cr) layers using the ANN model, whereas only the blue layer is able to classify the samples with higher than 90% accuracy using the PCA threshold model. The blue layer exhibits the highest accuracy of classification with both models, which establishes the strong classification ability of the same layer. This efficiency of classification reaches the highest level of about 94.4% using the ANN model, and 93.3% with the PCA threshold model. The luminance layer also yields the same highest efficiency of 94.4% using the ANN model, although the same efficiency with the PCA threshold model is much less at about 85.8%. The red, vital component and chrominance 1 (Cb) layers, on the other hand, displays reduced accuracy of classification, especially using the PCA threshold model, when the accuracy reduces beyond 80%. The red layer produces the least efficiency of about 83% with the ANN model and the Chrominance 1 (Cb) layer shows the same with a low classification accuracy of about 77% using the PCA threshold model.

The texture feature is obtained in this work using entropy filtering, where a 9 × 9 windowing method is applied to obtain the entropy value of the central pixel, and thereby, forming greyscale entropy-filtered image of the same dimension by running the window over the whole image. The efficiency of classification using the histogram of the entropy-filtered image is obtained almost equal using the two models of classifier, and the values being about 89% and 87.5% respectively using the ANN model and PCA threshold model respectively.

Analysis of Results Using Minor Features

The classifier accuracies obtained using the minor features such as mean, standard deviation (SD), entropy, kurtosis and skewness are shown graphically in Fig. 14.

Fig. 14
figure 14

Classifier accuracy obtained with ANN classifier using different minor features like mean, standard deviation (SD), entropy, kurtosis and skewness of different layers: red (R), green (G), blue (B), hue (H), saturation (S), vital component (V), luminance (Y), chrominance 1 (Cb), chrominance 2 (Cr) and complete RGB image (RGB)

Analysis of the minor features mostly show that the average classifier accuracy is highest with the mean values of almost all the layers of each colourmap, except for the Chrominance 1 (Cb) layer, where the accuracy is exceptionally poor at below 60%. In the case of blue and green layers, the same accuracy reaches as high as about 94.4%, which is even compared to the accuracy level reached using some of the major features using the ANN model. The classifier accuracy using the same mean feature is also found higher than 90% using other layers such as hue, vital component, luminance and the original RGB image. On the other hand, the kurtosis feature produces the least average accuracy of classification of less than 70% considering all the layers of each colourmap. The standard deviation (SD) feature yields the highest efficiency with the vital component layer and it ranges in the order of 86%, and the lowest accuracy for the same parameter being 61% using the blue layer. The highest and the lowest level of accuracy of classification, using the entropy feature has been found as about 89% and 63% using hue and blue layers respectively. Analysis of the kurtosis feature has produced the worst average accuracy considering all layers, with many of the results lying below 80% and 70% and even the same hue and blue layers have yielded an efficiency level of below 50%. The skewness feature has also yielded an average accuracy level of below 80%, similar to SD and entropy features, whereas the blue layer and the original RGB image have yielded an average accuracy level exceeding 90% using the same skewness feature.

Receiver Operating Characteristic Plot Evaluation

The performance of the proposed ANN classifier is exemplified with the help of the receiver operating characteristic (ROC) curve of Fig. 15, constructed with varying discrimination threshold and plotting TPR against FPR for every possible CUO (cut-off) value.

Fig. 15
figure 15

ROC curve for a B-ANN model and b Cr-kurtosis-ANN model

$${T}_{\mathrm{PR}}\left({\mathrm{CUO}}_{x}\right)={P}_{d}\left(\mathrm{RQ}\ge \mathrm{CUO}\left|{E}_{r}^{+}\right.\right)$$
(35)
$${F}_{\mathrm{PR}}\left({\mathrm{CUO}}_{x}\right)=P\left(\mathrm{RQ}\ge \mathrm{CUO}\left|{E}_{r}^{-}\right.\right)$$
(36)

where CUOx is the cut-off value at the position, Pd is the probability density, Er + and Er − are the positive and negative errors respectively and RQ are the quantitative results.

Thus, the representation of the ROC curve is as follows:

$$\mathrm{ROC}=\left\{{F}_{\mathrm{PR}}\left({\mathrm{CUO}}_{x}\right),{T}_{\mathrm{PR}}\left({\mathrm{CUO}}_{x}\right),\mathrm{CUO}\in \left(-\infty ,+\infty \right)\right\}$$
(37)

In terms of RQ, the ROC is described as follows:

$$\mathrm{ROC}=\left\{\left({R}_{\mathrm{Q}},\mathrm{ROC}\left({R}_{\mathrm{Q}}\right)\right), {R}_{\mathrm{Q}}\in \left(\mathrm{0,1}\right)\right\}$$
(38)

where the ROC maps RQ to TPR (CUOx) and CUOx matching to FPR (CUOx) = RQ.

The higher the area under the curve (AUC), the better the performance of the proposed classifier will be. Therefore, the model (build with the extracted features) with higher AUC is obviously the efficient one, as the ROC plot is built during the alteration in the scalar threshold value of the model (Lorente et al. 2013). The model constructed with the feature ‘B’ as the input layer has the highest AUC for the overall model as well as for the testing, training and validation set (Fig. 15a), the model built with the feature named kurtosis obtained from Cr channel possessed minimum AUC (Fig. 15b). Instead of measuring the absolute value, the AUC is unaltered with scale, thus able to determine the precision of the predictions. However, it is independent of the classification threshold. The eminence of the prediction is therefore illustrated by AUC irrespective of the classification threshold.

Conclusion

The proposed work illustrates an analysis for assessing the edibility of oyster mushrooms, using the images of two classes of samples, e.g. Fresh and Deteriorated. The present work uses two major analysis tools for this purpose. The first one is a statistical analysis model employing principal component analysis and the second one is an artificial neural network model. These models are used to analyze image features of each layer of the red (R)-green (G)-blue (B) colourmap, hue (H)-saturation (S)-vital component (V) colourmap, luminance (Y)-chrominance (Cb and Cr) colourmap, greyscale image and the entropy-filtered image. Observations reveal that the supervised learning model exceeds the statistical model in terms of the accuracy of classification. More so, some of the features show more than 90% accuracy of classification of the samples, which is, in fact, highly accurate for all real-life applications. Most importantly, the use of smartphones for capturing the sample images exhibits the possibility of widespread application and portability of the proposed algorithm.