|
On Feb 2, 2:19 pm, "kal " <kalyana...@gmail.com> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <2a58707d-29dd-4ef3-948f-77a8a1c5f...@k3g2000pbn.googlegroups.com>...
> > I wouldn't think saving a uint8 variable to a mat file and then
> > recalling it would change its class. Can you show the lines where you
> > called save() and load()?
>
> Here is my code: This is for loading 6 images in mat file
> T = zeros(50,300);
> Train_Number = 6; %Number of uniforms images per class
> j = 1;k = 50;
> TrainDatabasePath = uigetdir('Select images database path' );
> for i = 1 : Train_Number
> x = num2str(100 + mod(i,100));
> y = x(2:3);
> str = strcat('B-uniform', y);
> str = strcat('\',str,'.ppm');
> str = strcat(TrainDatabasePath,str);
> img = imread(str);
> img = rgb2gray(img);
> T(1:50,j:k) = img; j = j+50; k = k+50;
> end
> T = uint8(8);
> save T;
>
> Thanks,
> Kal
------------------------------------------------------
Yeah, that's not going to work. When you say this:
T = uint8(8);
save T;
you've just blown away your "T" and you're only saving the value 8. I
don't even know where you're saving it since you didn't give a mat
filename. Also this is not very robust code at all. For example you
don't have any check in there that the file actually exists. If it
doesn't your program will bomb. It's best to use something like
baseFileName = sprintf('B-uniform%s.ppm', y);
fullFileName = fullfile(TrainDatabasePath, baseFileName);
if exist(fullFileName, 'file')
% Stuff to do if the file actually exists.
img = imread(fullFileName);
img = rgb2gray(img);
T(1:50,j:k) = img;
% Increment j and k.
j = j+50;
k = k+50;
else
% Stuff to do if the file does not exist, for example warn the user
or log it to a file.
warningMessage = sprintf('Warning: %s does not exist',
fullFileName);
uiwait(warndlg(warningMessage));
end
Even then you're making assumptions, with out even checking, that your
image will have a size of 50 by 50 - again not a very robust way of
doing it. You should check those things before you just blindly blast
ahead and do them. A professional programmer would.
[rows columns numberOfColorChannels] = size(img);
if rows ~= 50 || columns ~= 50
img = imresize(img, [50 50]);
end
|