Dividing images of UCID database into 8x8 blocks
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
% This script has been used to create the training image dataset.
clear all;
close all;
UCIDPath='C:\Users\mayank\Desktop\JPEG\ucid.v2'; % select the path of UCID database
OutputPath='C:\Users\mayank\Desktop\JPEG\new'; % Where the 8x8 images will be stored
mkdir(OutputPath); % makes new directory
UCIDImages=dir([UCIDPath '*.tif']); % selects all the images of .tif extension from UCID path
UCIDImages={UCIDImages.name}; % returns the name of the images
PermInd=randperm(length(UCIDImages));
%randperm means random permutation
% select random images from the UCID database.
ImagesToUse=UCIDImages(PermInd); % use only those images in which are randomly selected in the previous step.
ImInd=0; % image index inititlaztion
ImagesCollected=0; % no of images taken from the UCID data set.
while ImagesCollected< 40; % select only less than 40 images
ImInd=ImInd+1; % increase the index by 1 in each iteration
im=imread([UCIDPath ImagesToUse{ImInd}]); % read the image selected as per the iteration
while ~(mod(size(im,1),64)==0 && mod(size(im,2),64)==0) % condition to check if it can be divided into 8x8 block grid.
disp('image size not divisible by 64, replacing');
ImInd=ImInd+1; % it this happens then move to the next image and check if it can be divided into 8x8 blocks.
im=imread([UCIDPath ImagesToUse{ImInd}]);
end
[~,filename,~]=fileparts(ImagesToUse{ImInd});
% actual syntax: [PATHSTR,NAME,EXT] = fileparts(FILE)
% here we are concerned about the Name of the file hence it will
% returns the file name for the specified file which is taken from
% ImagesTouse dataset.
for X=1:64:size(im,1) % selecting 8x8 from both X and Y direction
for Y=1:64:size(im,2)
block=im(X:X+63,Y:Y+63,:);
imwrite(block,[OutputPath filename '_' num2str(X) '_' ,num2str(Y) '.png']);
% creating 8x8 blocks of the image and save it into OutputPath
end
end
ImagesCollected=ImagesCollected+1; % move towards the next image
end
This shows following error:
>> CutTrainingImages
Warning: Directory already exists.
> In CutTrainingImages (line 8)
Index exceeds matrix dimensions.
Error in CutTrainingImages (line 21)
im=imread([UCIDPath ImagesToUse{ImInd}]); % read the image selected as per the iteration
Please help.
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!