How can I use semantic segmentation for gray scale images?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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!
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!