4d Array converting RGB image into binary
Show older comments
Hello, I want saved 3d images into a 4d array with following code:
for slice = 1 : length(filestrain)
filename = fullfile(foldertrain, filestrain(slice).name);
thisImage = imread(filename);
[rows, columns, numberOfColorChannels] = size(thisImage);
if numberOfColorChannels < 3
message = 'Error: Image is not RGB Color!';
uiwait(warndlg(message));
continue;
end
if rows ~= 1603 || columns ~= 1603
message = 'Error: Image is not 1603X1603!';
uiwait(warndlg(message));
continue; % Skip this image.
end
% Image is okay. Insert it.
XTrain(:,:,:,slice) = thisImage;
imshow(thisImage)
end
The images are zero padded images (1603x1603x3). The original images all have different sizes (cutted manually) and are partly very small like 321x97x3. I did this zero padding for the Input layer of a CNN.
when I am trying to display some images from the 4d Array with:
imshow(XTrain(:,:,2))
The image which is shown is like a binary image no RGB. I dont understand why. Is there a problem with the size of the images?
Thanks for your help
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!