load images and their references

Can anyone help me to plot graph by using grid2image command by loading images and their references with their names from a single mat file with two different variables names. I have attached the code in which mat file is generated
start_path='F:\study\practise\New folder\2015';
topLevelFolder = start_path;
if topLevelFolder == 0
return;
end
filePattern_1 = sprintf('%s/**/HH/', topLevelFolder);
filePattern = sprintf('%s/*.tif', filePattern_1);
allFileInfo = dir(filePattern);
isFolder = [allFileInfo.isdir];
allFileInfo(isFolder) = [];
listOfFolderNames = unique({allFileInfo.folder});
numberOfFolders = length(listOfFolderNames);
fprintf('The total number of folders to look in is %d.\n', numberOfFolders);
totalNumberOfFiles = length(allFileInfo);
if totalNumberOfFiles >= 1
for k = 1 : totalNumberOfFiles
% Go through all those files.
thisFolder = allFileInfo(k).folder;
thisBaseFileName = allFileInfo(k).name;
fullFileName = fullfile(thisFolder, thisBaseFileName);
% fprintf(' Processing file %d of %d : "%s".\n', k, totalNumberOfFiles, fullFileName);
% To get images and their georeferencing
[A,R]=geotiffread(fullFileName);
Y= db2pow(A );
% % To apply median filter
B = medfilt2(Y,[100 100]);
%
% To apply block averaging
% meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:)) * ones(2,2, class(theBlockStructure.data));
meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:));
blockSize = [12 12];
blockyImage = blockproc(B, blockSize, meanFilterFunction);
blockyImage(isnan(blockyImage))=0;
X= pow2db(blockyImage);
% % To save images and their names as a single mat file
Alpha(k).name=thisBaseFileName;
Alpha(k).img=X;
%
% Get lat and lon of blocked images
R_blocked = R;
R_blocked.RasterSize = size(X);
% %To save georeferencing of all images as a single mat file
% R2.name=thisBaseFileName;
R2(k).name=thisBaseFileName;
R2(k).Georeferencing=R_blocked;
save('Preprocessed2015.mat','Alpha', 'R2');
clear X
end
else
end

6 Comments

Can you format your text? Back in MATLAB type control-a (to select all), then control-I (to fix the indenting). Then copy and paste back here so we can read it.
Sorry I couldnot understand this.
Can anyone help me to plot graph by using grid2image command by loading images and their references with their names from a single mat file with two different variables names. I have attached the code in which mat file is generated
start_path='F:\study\practise\New folder\2015';
topLevelFolder = start_path;
if topLevelFolder == 0
return;
end
filePattern_1 = sprintf('%s/**/HH/', topLevelFolder);
filePattern = sprintf('%s/*.tif', filePattern_1);
allFileInfo = dir(filePattern);
isFolder = [allFileInfo.isdir];
allFileInfo(isFolder) = [];
listOfFolderNames = unique({allFileInfo.folder});
numberOfFolders = length(listOfFolderNames);
fprintf('The total number of folders to look in is %d.\n', numberOfFolders);
totalNumberOfFiles = length(allFileInfo);
if totalNumberOfFiles >= 1
for k = 1 : totalNumberOfFiles
% Go through all those files.
thisFolder = allFileInfo(k).folder;
thisBaseFileName = allFileInfo(k).name;
fullFileName = fullfile(thisFolder, thisBaseFileName);
% fprintf(' Processing file %d of %d : "%s".\n', k, totalNumberOfFiles, fullFileName);
% To get images and their georeferencing
[A,R]=geotiffread(fullFileName);
Y= db2pow(A );
% % To apply median filter
B = medfilt2(Y,[100 100]);
%
% To apply block averaging
% meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:)) * ones(2,2, class(theBlockStructure.data));
meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:));
blockSize = [12 12];
blockyImage = blockproc(B, blockSize, meanFilterFunction);
blockyImage(isnan(blockyImage))=0;
X= pow2db(blockyImage);
% % To save images and their names as a single mat file
Alpha(k).name=thisBaseFileName;
Alpha(k).img=X;
%
% Get lat and lon of blocked images
R_blocked = R;
R_blocked.RasterSize = size(X);
% %To save georeferencing of all images as a single mat file
% R2.name=thisBaseFileName;
R2(k).name=thisBaseFileName;
R2(k).Georeferencing=R_blocked;
save('Preprocessed2015.mat','Alpha', 'R2');
clear X
end
else
end
I have also attached the code to plot a graph.
X = cell2mat(struct2cell(load('F:\study\practise\New folder\2010\script\preprocessed2010.mat', 'Alpha')));
Y= load('F:\study\practise\New folder\2010\script\preprocessed2010.mat', 'R2');
for k=1:length(X)
% %
b=X(k).img;
b(b==0)=NaN;
b (b > -5) = NaN;
b (b < -32) = NaN;
% % % Get edges
A = edge(b, 'canny');
% % % apply morphological function
BW3 = bwmorph(A,'bridge');
A3 = bwareaopen(BW3, 100);
figure, temp1 = grid2image(A3, R2); title([num2str(k),': ', Alpha(k).name]);
end
Look how all your left hand margins are not aligned properly. I did what I said control-a, control-i and pasted back here. Look, doesn't the code below have a better indenting/formatting than what you pasted originally? The left margins now start where they should rather than being a random jumble of starting columns.
start_path='F:\study\practise\New folder\2015';
topLevelFolder = start_path;
if topLevelFolder == 0
return;
end
filePattern_1 = sprintf('%s/**/HH/', topLevelFolder);
filePattern = sprintf('%s/*.tif', filePattern_1);
allFileInfo = dir(filePattern);
isFolder = [allFileInfo.isdir];
allFileInfo(isFolder) = [];
listOfFolderNames = unique({allFileInfo.folder});
numberOfFolders = length(listOfFolderNames);
fprintf('The total number of folders to look in is %d.\n', numberOfFolders);
totalNumberOfFiles = length(allFileInfo);
if totalNumberOfFiles >= 1
for k = 1 : totalNumberOfFiles
% Go through all those files.
thisFolder = allFileInfo(k).folder;
thisBaseFileName = allFileInfo(k).name;
fullFileName = fullfile(thisFolder, thisBaseFileName);
% fprintf(' Processing file %d of %d : "%s".\n', k, totalNumberOfFiles, fullFileName);
% To get images and their georeferencing
[A,R]=geotiffread(fullFileName);
Y= db2pow(A );
% % To apply median filter
B = medfilt2(Y,[100 100]);
%
% To apply block averaging
% meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:)) * ones(2,2, class(theBlockStructure.data));
meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:));
blockSize = [12 12];
blockyImage = blockproc(B, blockSize, meanFilterFunction);
blockyImage(isnan(blockyImage))=0;
X= pow2db(blockyImage);
% % To save images and their names as a single mat file
Alpha(k).name=thisBaseFileName;
Alpha(k).img=X;
%
% Get lat and lon of blocked images
R_blocked = R;
R_blocked.RasterSize = size(X);
% %To save georeferencing of all images as a single mat file
% R2.name=thisBaseFileName;
R2(k).name=thisBaseFileName;
R2(k).Georeferencing=R_blocked;
save('Preprocessed2015.mat','Alpha', 'R2');
clear X
end
else
end
ok thnx alot to guide me. Now, kindly help me to write code.
I don't have geotiffread(). Is that in the Mapping Toolbox (which I don't have)?

Sign in to comment.

Answers (0)

Asked:

on 11 Dec 2020

Commented:

on 13 Dec 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!