2000 nmr sequences contain noise wavelet coefficient as a cnn input and the corresponding clean nmr sequences wavelet coefficient as the output in matlab

  1. Load and preprocess the data:
main.m
% set the path to the folder containing the raw data
path = 'path/to/folder';
% create a datastore to efficiently read and process the data
ds_noisy = imageDatastore(path, 'FileExtensions', '.mat', 'ReadFcn', @load);
% update the datastore read function to extract the wavelet coefficients
ds_noisy.ReadFcn = @(x) wcodemat(x.noisy,255);

% repeat for the clean data
ds_clean = imageDatastore(path, 'FileExtensions', '.mat', 'ReadFcn', @load);
ds_clean.ReadFcn = @(x) wcodemat(x.clean,255);

% define data splits for training/validation/testing
[ds_noisy_train,ds_noisy_val,ds_noisy_test] = splitEachLabel(ds_noisy,0.7,0.15,0.15);
[ds_clean_train,ds_clean_val,ds_clean_test] = splitEachLabel(ds_clean,0.7,0.15,0.15);
716 chars
15 lines
  1. Define the CNN architecture:
main.m
% define the CNN layers
layers = [
    imageInputLayer([size(ds_noisy.Files{1},1) size(ds_noisy.Files{1},2) 1])
    convolution2dLayer(3,32,'Padding','same')
    reluLayer
    maxPooling2dLayer(2,'Stride',2)
    convolution2dLayer(3,64,'Padding','same')
    reluLayer
    maxPooling2dLayer(2,'Stride',2)
    convolution2dLayer(3,128,'Padding','same')
    reluLayer
    transposedConv2dLayer(4,128,'Stride',2,'Cropping',1)
    convolution2dLayer(3,64,'Padding','same')
    reluLayer
    transposedConv2dLayer(4,64,'Stride',2,'Cropping',1)
    convolution2dLayer(3,32,'Padding','same')
    reluLayer
    convolution2dLayer(3,1,'Padding','same')
    regressionLayer];
665 chars
20 lines
  1. Train the CNN:
main.m
% define the training options
options = trainingOptions('adam', ...
    'InitialLearnRate', 1e-3, ...
    'MaxEpochs', 20, ...
    'MiniBatchSize', 128, ...
    'Shuffle', 'every-epoch', ...
    'ValidationData', {ds_noisy_val,ds_clean_val}, ...
    'ValidationFrequency', 50, ...
    'Verbose', false);

% train the network
net = trainNetwork(ds_noisy_train,ds_clean_train,layers,options);
391 chars
13 lines
  1. Test the CNN:
main.m
% get predictions on the test set
predicted_clean = predict(net,ds_noisy_test);

% visualize some example results
idx = randperm(numel(ds_noisy_test.Files),5);
for i = 1:5
    % load the noisy and ground-truth clean images
    noisy = read(ds_noisy_test(idx(i)));
    clean = read(ds_clean_test(idx(i)));
    % reshape the predicted image to match the original size
    pred = reshape(predicted_clean(:,:,:,idx(i)),[size(ds_noisy_test.Files{1},1) size(ds_noisy_test.Files{1},2)]);
    % visualize the results
    subplot(1,3,1); imshow(noisy,[]); title('Noisy');
    subplot(1,3,2); imshow(clean,[]); title('Ground truth');
    subplot(1,3,3); imshow(pred,[]); title('Predicted');
    pause;
end
696 chars
18 lines

related categories

gistlibby LogSnag