Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ngohlong authored Oct 6, 2021
1 parent 3eeb5fc commit 144c879
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 92 deletions.
5 changes: 1 addition & 4 deletions training/recurse_dwt_isic17_final.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
% Start with a folder and get a list of all subfolders.
% Finds all images in that folder and all of its subfolders
% mix the training, validation and test set together to obtain two classes
% benign and malignant
tic;
Expand Down Expand Up @@ -61,5 +59,4 @@
%% save data
fn = strcat('data/myISICcr80plus256_Wavelet1.mat');
save(fn, 'Yw', 'Yw_range', '-v7.3');
toc;
% end
toc;
16 changes: 8 additions & 8 deletions training/recurse_dwt_isic17_malignant.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% get additional malignant images from ISIC18 and add to the ISIC17
% get additional malignant images from ISIC Archive
% database to balance the two classes (benign and malignant)
tic;
clear all; close all;
Expand All @@ -20,6 +20,7 @@
imgSubMat = [];%imgSubMat1 = [];
if (mySubDirs(i).isdir == 1) %myRootDir might have files as well
currentSubDir = fullfile(myRootDir, mySubDirs(i).name);

%get all filenames that match myFilePattern
myFiles = dir(fullfile(currentSubDir, myFileExtension));
numFiles = length(myFiles);
Expand All @@ -30,6 +31,7 @@
numPreviousFiles = length(previousFiles);
position = position + numPreviousFiles;
end

%read all files in sub directory and transform to wavelet space
for k = 1:(numFiles)
fileName = myFiles(k).name;
Expand All @@ -39,29 +41,27 @@
Xgray = rgb2gray(X);
end
[m, n] = size(Xgray);

% crop the image first
r = 0.8; % ratio between cropped image and the original one
p = round(r*m); q = round(r*n);
xmin = round((m-p)/2);
ymin = round((n-q)/2);
win = [xmin ymin p q];
Xcr = Xgray(xmin:p, ymin:q);

% resize the image
Xfin = imresize(Xcr, [256, 192], 'bicubic'); %192x256 or 256x192 or 600x450 or 256x256 or 128x96
Xfin = imresize(Xcr, [256, 192], 'bicubic');
% =========================================================================
[cA1, cH1, cV1, cD1] = dwt2(Xfin,'db1'); %haar transformation

cA1_tmp(:,k+position) = double(cA1(:));
% cH1_tmp(:,k+position) = double(cH1(:));
% cV1_tmp(:,k+position) = double(cV1(:));
% cD1_tmp(:,k+position) = double(cD1(:));
cA1_tmp(:,k+position) = double(cA1(:));
Y_label(k+position) = 1;
end
end
end

Y = cA1_tmp;
%% save data

fn = strcat('data/myISIC_test_cr80plus_256x192.mat' );
save(fn, 'Y', 'Y_label', '-v7.3');
16 changes: 7 additions & 9 deletions training/recurse_dwt_isic17_mela.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
clear all; close all;
addpath(genpath('data'));
addpath('utils');
mode = 3;
mode = 3; % choose mode to get the data from the training/validation/test set

switch mode
case 1
Expand All @@ -27,7 +27,6 @@
imgSubMat_mela = []; imgSubMat_benign = [];
tmp_label_mela = []; tmp_label_benign = [];
s = 1; t = 1;
%%% recurse sub-directories

%% get all filenames that match�myFilePattern
myFiles = dir(fullfile(myRootDir, myFileExtension));
Expand All @@ -51,12 +50,12 @@
Xcr = Xgray(xmin:p, ymin:q);

% resize the image
Xfin = imresize(Xcr, [256, 192], 'bicubic'); %192x256 or 256x192 or 600x450 or 256x256 or 128x96
% or 230x172 or 272x204
% wavelet decomposition in quaternions
[cA1,cH1,cV1,cD1] = dwt2(Xfin, 'db1'); %daubechies transformation
Xfin = imresize(Xcr, [256, 192], 'bicubic');

% wavelet decomposition
[cA1,cH1,cV1,cD1] = dwt2(Xfin, 'db1'); % haar transformation
tmp = double(cA1(:));
% tmp = double(cD1(:));

if groundTruth(i,1)==1;
imgSubMat_mela(:,s) = tmp;
tmp_label_mela(s) = 1;
Expand All @@ -81,5 +80,4 @@
fn = strcat('data/myISIC17-PhiHatVF_test_256x192.mat');
end
save(fn, 'Y', 'Y_label', '-v7.3');
toc;
% end
toc;
85 changes: 14 additions & 71 deletions training/recurse_dwt_sub.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
% function [imgMat, imgMat_range] = recurse_dwt_sub(myRootDir, mySubDirPattern, myFileExtension)
% Start with a folder and get a list of all subfolders.
% Finds all images in that folder and all of its subfolders
% tic;

tic;
clear all; close all;

addpath(genpath('utils'));
Expand All @@ -22,92 +20,47 @@
mySubDirPattern = 'obj*';
myFileExtension = '*.png';
case 4
myRootDir = './data/myFlower17';
mySubDirPattern = 'flower_*';
myFileExtension = '*.jpg';
case 5
myRootDir = './data/Cropped_ARgender';
mySubDirPattern = '*';
myFileExtension = '*.bmp';
case 6
% myRootDir = './data/coil-100_PhiHatVF_PNG';
myRootDir = './data/coil-100_PsiHatVF_PNG';
% myRootDir = './data/coil-100_PGVF_PNG';
mySubDirPattern = 'obj*';
myFileExtension = '*.png';
case 7
myRootDir = './data/Cropped_Yale_PhiHat_Large';
mySubDirPattern = 'yaleB*';
myFileExtension = '*.png';
case 8
myRootDir = './data/ISIC2018_PhiHatVF';
mySubDirPattern = '*';
myFileExtension = '*.png';
end

mySubDirs = dir(fullfile(myRootDir, mySubDirPattern));
mySubDirs = mySubDirs(~ismember({mySubDirs.name},{'.','..'}));
numSubDirs = length(mySubDirs);
imgMat = []; %imgMat1 = [];
imgMat = [];
imgMat_range = 0;
%recurse sub-directories

%% recurse sub-directories
for i = 1:numSubDirs
imgSubMat = [];%imgSubMat1 = [];
if (mySubDirs(i).isdir == 1) %myRootDir might have files as well
if (mySubDirs(i).isdir == 1) % myRootDir might have files as well

currentSubDir = fullfile(myRootDir, mySubDirs(i).name);

%get all filenames that match myFilePattern
% get all filenames that match myFilePattern
myFiles = dir(fullfile(currentSubDir, myFileExtension));
numFiles = length(myFiles);

%read all files in sub directory and transform to wavelet space
% read all files in sub directory and transform to wavelet space
for k = 1:(numFiles)
fileName = myFiles(k).name;
fullFileName = fullfile(currentSubDir, fileName);
X = imread(fullFileName);
if size(X,3)==3
X = rgb2gray(X);
% X = rgb2ycbcr(X);
% X = X(:,:,1);
end
% =========== Resize training images ======================================
if database == 6
% X = imresize(X, [64, 64], 'bicubic');
X = imresize(X, [420, 420], 'bicubic');
elseif database == 7
X = imresize(X, [384, 336], 'bicubic');
elseif database == 8
% [m, n] = size(X);
% r = 0.8; % ratio between cropped image and the original one
% p = round(r*m); q = round(r*n);
% xmin = round((m-p)/2) +1;
% ymin = round((n-q)/2) +1;
% win = [xmin ymin p q];
% X = X(xmin:p, ymin:q);
X1 = imresize(X, [500, 500], 'bicubic');
% % crop the image to size [pxq]
% [m, n] = size(X);
% p = 500; q = 500;
% xmin = round((m-p)/2)+1; xmax = xmin + p -1;
% ymin = round((n-q)/2)+1; ymax = ymin + p -1;
% win = [xmin ymin xmax ymax];
% X2 = X(xmin:xmax, ymin:ymax);
end
% =========================================================================
% ===========================================================
[cA1,~,~,~] = dwt2(X1,'db1'); %daubechies transformation
% [cA2,~,~,~] = dwt2(X2,'db1'); %daubechies transformation
cA1_tmp = double(cA1(:));
% cA2_tmp = double(cA2(:));
% cD_tmp = double(cD(:));
imgSubMat(:,k) = cA1_tmp;
% imgSubMat(:,k + numFiles) = cA2_tmp;
end
imgMat = [imgMat imgSubMat]; %imgMat1 = [imgMat1 imgSubMat1];
imgMat = [imgMat imgSubMat];
imgMat_range(i+1) = imgMat_range(i) + k;
end
end
% PCA dimensionality reduction

%% PCA dimensionality reduction
C = double(imgMat * imgMat');
[V, D] = eig(C);
D = diag(D); % perform PCA on features matrix
Expand All @@ -117,6 +70,7 @@
imgMat_pca = V_pca' * imgMat;
Yw = imgMat_pca; Yw_range = imgMat_range;

%% save data
switch database
case 1
fn = strcat('data/myYaleB_Wavelet1.mat');
Expand All @@ -125,18 +79,7 @@
case 3
fn = strcat('data/myCoil-100_Wavelet1.mat' );
case 4
fn = strcat('data/myFlower_Wavelet1');
case 5
fn = strcat('data/myARgender_Wavelet1');
case 6
fn = strcat('data/myCoil-100_PsiHatVF_resize420x420_Wavelet1.mat');
% fn = strcat('data/myCoil-100_PhiHatVF_resize64x64_Wavelet1.mat');
% fn = strcat('data/myCoil-100_PGVF_Wavelet1.mat');
case 7
fn = strcat('data/myYaleB_PhiHatVF_Large_Wavelet1.mat');
case 8
fn = strcat('data/myISIC2018_PhiHatVF_resize500x500_Wavelet1.mat');
end
save(fn, 'Yw', 'Yw_range');
%toc;
% end
toc;

0 comments on commit 144c879

Please sign in to comment.