cnn for feature extraction

90 views (last 30 days)
Athulya N
Athulya N on 13 Dec 2019
Answered: Shahram Taheri on 19 Jul 2022
i am doing project on image classification.i have converted image in R,G and B i need to extract features from each channel using can i use cnn for feature extraction in image.

Answers (3)

Sourav Bairagya
Sourav Bairagya on 16 Dec 2019
As you have your RGB images ready, then you can define your custom convolutional neural network using 'dlNetwork' object and train it to extract features out of it.
For training you can leverage this link:
For extracting feature from the trained network, use 'predict' function. To know more about this leverage this link:

esther MUKOYA
esther MUKOYA on 25 Jan 2021
Kindly could you share on the method used to convert the images to RGB?

Shahram Taheri
Shahram Taheri on 19 Jul 2022
imds = imageDatastore('Your Dataset PATH', ...
imds = shuffle(imds);
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7);
net = resnet18;
inputSize = net.Layers(1).InputSize;
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain,'ColorPreprocessing','gray2rgb');
augimdsTest = augmentedImageDatastore(inputSize(1:2),imdsValidation,'ColorPreprocessing','gray2rgb');
layer = 'pool5';
featuresTrain = activations(net,augimdsTrain,layer,'OutputAs','rows');
featuresTest = activations(net,augimdsTest,layer,'OutputAs','rows');
YTrain = imdsTrain.Labels;
YTest = imdsValidation.Labels;
classifier = fitcecoc(featuresTrain,YTrain);
YPred = predict(classifier,featuresTest);

Community Treasure Hunt

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

Start Hunting!

Translated by