How to prepare hyperspectral image data for convolutional neural network?
5 views (last 30 days)
In order to run convolutional neural network in neural network toolbox with grey or color image data, I can easily segment the images and locate them into proper category folders for datastore command.
But now I wonder how to run CNN with hyperspectral images as they have more than 3 channels and different file formats (.hyp or .img). Any hint or clue would be appreciated.
Parth Parikh on 30 Nov 2022
We can crop the data and feed into augmentedImageDatastore. Suppose for the classification problem we would like to pass labels and hyperspectral data to datastore. Assume hyperspectral datacube size is 145x145x100 and label matrix size is 145x145.
% hcube = 3D datacube of size 145x145x100
% groundTruthLabel = 2D matrix of size 145x145.
winSize = 20;
padding = floor((winSize-1)/2);
zeroPaddingPatch = padarray(hcube,[padding,padding],0,'both');
[rows,cols,ch] = size(hcube);
patchData = zeros(rows*cols,winSize,winSize,ch);
patchLabel = zeros(rows*cols,1);
zeroPaddedInput = size(zeroPaddingPatch);
patchIdx = 1;
for i= (padding+1):(zeroPaddedInput(1)-padding)
for j= (padding+1):(zeroPaddedInput(2)-padding)
patch = zeroPaddingPatch(i-padding:i+padding,j-padding:j+padding,:);
patchData(patchIdx,:,:,:) = patch;
patchLabel(patchIdx,1) = groundTruthLabel(i-padding,j-padding);
patchIdx = patchIdx+1;
[allPatches,allLabels] = createImagePatchesFromHypercube(patchData,patchLabel,winSize);
We can partition allPatches and allLabels for traning and testing.
Similar example is available in hyperspectral support package: