Image Classification using Percentage

We are working on a project. The goal of the project is to calculate the ratio (in percentage) of musillage in photos. I successfully classified whether a phot has musillage or not (%0 or %100) but not any number in between. The photos are classified using image labeling. The code is attached, woul you please suggest how to improve the working code to cover the percentage of musillages. Two photos of both classes are attached.
Thanks in advance
++
clear all; clc;
imds = imageDatastore("C:\Users\fatih.yigit\OneDrive - ALTINBAS UNIVERSITY\Project 10\project10\Musillage_Photos", ...
IncludeSubfolders=true, ...
LabelSource="foldernames");
numTrainFiles = 25;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,"randomized");
classNames = categories(imdsTrain.Labels);
inputSize = [300 300 3];
numClasses = 2;
layers = [
imageInputLayer(inputSize)
convolution2dLayer(20,50)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
options = trainingOptions("sgdm", ...
MaxEpochs=50, ...
ValidationData=imdsValidation, ...
ValidationFrequency=30, ...
Plots="training-progress", ...
Metrics="accuracy", ...
Verbose=false);
net = trainnet(imdsTrain,layers,"crossentropy",options);
scores = minibatchpredict(net,imdsValidation);
YValidation = scores2label(scores,classNames);
++

5 comentarios

Image Analyst
Image Analyst el 16 de Feb. de 2025
Editada: Image Analyst el 16 de Feb. de 2025
I don't understand this question about your college project at all. Here is the definition
"mu·ci·lage ˈmyü-s(ə-)lij. 1. : a gelatinous substance of various plants (as legumes or seaweeds) that contains protein and polysaccharides and is similar to plant gums. 2. : an aqueous usually viscid solution (as of a gum) used in pharmacy as an excipient and in medicine as a demulcent."
So the first problem is you posted photos of sky, beach, ocean, buildings, and ships. What is your definition of mucilage? Where is it in the photos you attached?
Problem #2 is that you seem to want to use deep learning to segment out the mucilage yet you gave us only 2 training photos, no ground truth photos, no validation photos, and no test photos. You can't do training with only 2 photos and no ground truth information. It could be possible to do traditional image analysis with only two photos but you need to give a good definition of what you want to segment.
Third problem is that you say "Two photos of both classes are attached." when no such photos are attached.
Fourth problem is that even if you had a percentage of the scene covered in mucilage, the percentage would have no meaningful use with those photos because of the scene and field of view, and especially what's in the field of view. There is no action that you could take based on the percentage. For example you can't say that if the percentage is more than 50% of the picture, I need to clean my beach (or ship or whatever) when you have buildings, mountains, and other stuff in there which would never get covered by mucilage.
Fatih
Fatih el 16 de Feb. de 2025
Soory for the confusion. The photos are examples. The first one is a clear sea witout any musillage (0%) and the second one has a lot (80%). But the trained model has only two outputs regardless of the amound like binary (0-0% or 1-100%). I want to have values between two, if there is some 35% or 50% etc.
Those photos are just examples of possible outputs. I have 100 photos and an come up with more. So it is not about the training dataset. Regaring third problem, foto1 - No Musillage(0% according to my code), MUCI... Mucillage(100% again according to my code). For example, new photo (60%.jpeg) should have an output of around 60% based on the amount of musillage seen.
For the fourth question, I expect to have the amount of musilage in the sea, which is identical in color. So for the use we have ideas but percentage output is important that can be used for an input of another area.
Thanks in advance.
Image Analyst
Image Analyst el 16 de Feb. de 2025
Snapshots taken with various viewpoints cannot give accurate percentages. You would need overhead photos of the whole sea area. Even then, the percentage of blue or green that is covered by brown or white gunk depends on how much of the sea/ocean you include. If you double the amount of clear sea water in the scene (by zooming out) then you increase the area of clear water and the gunk stays the same so the percentage goes down even though the amount of gunk didn't change. And how did you determine the ground truth percentage for each photo? Just guessed? Hand traced the gunk and ocean regions? Some other way?
Fatih
Fatih el 17 de Feb. de 2025
Actually I labeled the mucillage regions manually using the image labeler.
imds = imageDatastore("C:\Users\fatih.yigit\OneDrive - ALTINBAS UNIVERSITY\Project 10\project10\Musillage_Photos", ...
IncludeSubfolders=true, ...
LabelSource="foldernames");
You are getting your labels from the foldernames, not from ground-truth labels.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Feb. de 2025
classNames = categories(imdsTrain.Labels);
That tells us that the class names are categoricals. It is doubtful that the class names happen to be "000%", "001%", "002%" ... "010%", "011%" ... all the way to "099%" and "100%" -- you simply don't have enough training images to be that fine grained. If you do have numbered categories, it is more likely something like "0%", "10%", "20%", up to "90%" then "100%". But categories are internally ordered alphabetically rather than by extracting embedded numbers, so the order would more likely come out as "0%", "10%", "100%", "20%", "30%" up to "90%". The ordering is weak, and so cannot really be used predictively
Now, your images are not internally labeled as to whether parts are musillage or not, so the processing is free to pick out any part to focus on. The processing could, for example, end up focusing on "mountains" and end up ignoring the musillage.

1 comentario

Fatih
Fatih el 17 de Feb. de 2025
Actually I labeded photos using Imagelabeler while selecting musillage areas. They may not be perfect but gives an idea. So if there is better way, I am also comfortable to ignore what I did and start from scratch including more photos.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 16 de Feb. de 2025

Comentada:

el 17 de Feb. de 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by