How can I use semantic segmentation for gray scale images?

4 ビュー (過去 30 日間)
Abbas Atefi
Abbas Atefi 2018 年 10 月 2 日
コメント済み: soheib hadj moussa 2020 年 4 月 14 日
Hi,
I labeled gray scale images using Pixel Label in Image Labeler app (MATLAB 2018a). I am using semantic segmentation (https://www.mathworks.com/help/vision/examples/semantic-segmentation-using-deep-learning.html) to classify different objects in the images. When I ran this part of the code (I changed the third element in the imageSize to 1 because I am using the gray scale images):
imageSize = [144 176 1];
numClasses = numel(classes);
lgraph = segnetLayers(imageSize,numClasses,'vgg16');
I got this error:
imageSize must have three elements and the third element must be 3 when creating SegNet based off of VGG-16 or VGG-19.
Error in segnetLayers (line 170)
iCheckImageSizeHasThreeElementsForVGG(args.imageSize);
Error in semanticSegmentation (line 23)
lgraph = segnetLayers(imageSize,numClasses,'vgg16');
Does SegNet support gray scale images? If yes, how can I solve the issue?
Thank you,
Abbas
  1 件のコメント
Aydin Sümer
Aydin Sümer 2018 年 10 月 30 日
Did you solve this problem ? I'm getting same errror.

サインインしてコメントする。

回答 (1 件)

Andrey Gizdov
Andrey Gizdov 2018 年 11 月 27 日
編集済み: Andrey Gizdov 2018 年 11 月 27 日
Hi,
I was having exactly the same issue as you. To solve it, I created a simple functions which checks for the number of color channels in each of image of the 'imds' ImageDatastore from your example. The function is as follows:
function [] = checkDataSize(imds)
%Check if all provided training images are in RGB format
imagesPath = [imds.Files];
for i=1:numel(imagesPath)
currentImage = readimage(imds, i);
[~, ~, colorChannels] = size(currentImage);
if colorChannels == 1 || colorChannels == 2
newImage = cat(3, currentImage, currentImage, currentImage);
imwrite(newImage, imagesPath{i});
fprintf("Found and overwrote image with a single color channel in path %s \n", imagesPath{i});
end
end
end
Probably not the best solution, but it works around the problem and did the trick for me.
Hope that helps!
  1 件のコメント
soheib hadj moussa
soheib hadj moussa 2020 年 4 月 14 日
i have the same problem have u solution?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by