Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to determine specific image is empty in a specific folder

Subject: How to determine specific image is empty in a specific folder

From: Zulkifli

Date: 18 Feb, 2010 15:35:22

Message: 1 of 9

Hi all,

I try to use isempty, but i won't work. What i'm trying to do firstly to call the folder directory where images is stored using the following command

bandpath = 'C:\System\band files';

then i specify the image i want using the following command

bandFiles = dir(fullfile(bandpath, 'band2.JPG'));

Then i'm stuck.

what i'm trying to do next is to use if-else statement.

where, if the 'band2.JPG' exist, the it will imshow('band2.JPG')

else

warndlg('No file recorded!!!','!! Warning !!');
break;

end

the problem is that, i do not know how to write a code to justify that the band2.JPG
exist. pls help. thanks

Subject: How to determine specific image is empty in a specific folder

From: Sadik

Date: 18 Feb, 2010 15:47:05

Message: 2 of 9

Hi Zulkifli,

isempty should work. Can you write some examples of your bandFiles variable? What is it usually assigned? If it band2.jpg does not exist, bandFiles should equal 0x1 struct array.

Best.

"Zulkifli " <zulkifliaziz@yahoo.com> wrote in message <hljmnq$933$1@fred.mathworks.com>...
> Hi all,
>
> I try to use isempty, but i won't work. What i'm trying to do firstly to call the folder directory where images is stored using the following command
>
> bandpath = 'C:\System\band files';
>
> then i specify the image i want using the following command
>
> bandFiles = dir(fullfile(bandpath, 'band2.JPG'));
>
> Then i'm stuck.
>
> what i'm trying to do next is to use if-else statement.
>
> where, if the 'band2.JPG' exist, the it will imshow('band2.JPG')
>
> else
>
> warndlg('No file recorded!!!','!! Warning !!');
> break;
>
> end
>
> the problem is that, i do not know how to write a code to justify that the band2.JPG
> exist. pls help. thanks

Subject: How to determine specific image is empty in a specific folder

From: Zulkifli

Date: 18 Feb, 2010 15:56:05

Message: 3 of 9

Thanks Sadik,

The thing is that in the folder not consist only one image. there are a few of them, how can determine which file i'm took?
"Sadik " <sadik.hava@gmail.com> wrote in message <hljndp$ofq$1@fred.mathworks.com>...
> Hi Zulkifli,
>
> isempty should work. Can you write some examples of your bandFiles variable? What is it usually assigned? If it band2.jpg does not exist, bandFiles should equal 0x1 struct array.
>
> Best.
>
> "Zulkifli " <zulkifliaziz@yahoo.com> wrote in message <hljmnq$933$1@fred.mathworks.com>...
> > Hi all,
> >
> > I try to use isempty, but i won't work. What i'm trying to do firstly to call the folder directory where images is stored using the following command
> >
> > bandpath = 'C:\System\band files';
> >
> > then i specify the image i want using the following command
> >
> > bandFiles = dir(fullfile(bandpath, 'band2.JPG'));
> >
> > Then i'm stuck.
> >
> > what i'm trying to do next is to use if-else statement.
> >
> > where, if the 'band2.JPG' exist, the it will imshow('band2.JPG')
> >
> > else
> >
> > warndlg('No file recorded!!!','!! Warning !!');
> > break;
> >
> > end
> >
> > the problem is that, i do not know how to write a code to justify that the band2.JPG
> > exist. pls help. thanks

Subject: How to determine specific image is empty in a specific folder

From: Sadik

Date: 18 Feb, 2010 16:08:05

Message: 4 of 9

Actually you are taking the one which you are calling.

I guess you want to see if there are any files whose names start with "band".

Then, you should do

bandFiles = dir(fullfile(bandpath, 'band*.JPG'));

The asterisk here will have you pick all the images with name bandx.jpg [x is any number or text, band1.jpg, band2.jpg, band434234.jpg, band_ale.jpg will all be put into bandFiles].

Once you have them,

if ~isempty(bandFiles)
    for k = 1:length(bandFiles)
        figure(k) % Open up a new figure window
        imshow(fullfile(bandpath, bandFiles(k).name));
    end
else
    disp(['No band files in ' bandpath]);
end

Best.





"Zulkifli " <zulkifliaziz@yahoo.com> wrote in message <hljnul$suf$1@fred.mathworks.com>...
> Thanks Sadik,
>
> The thing is that in the folder not consist only one image. there are a few of them, how can determine which file i'm took?
> "Sadik " <sadik.hava@gmail.com> wrote in message <hljndp$ofq$1@fred.mathworks.com>...
> > Hi Zulkifli,
> >
> > isempty should work. Can you write some examples of your bandFiles variable? What is it usually assigned? If it band2.jpg does not exist, bandFiles should equal 0x1 struct array.
> >
> > Best.
> >
> > "Zulkifli " <zulkifliaziz@yahoo.com> wrote in message <hljmnq$933$1@fred.mathworks.com>...
> > > Hi all,
> > >
> > > I try to use isempty, but i won't work. What i'm trying to do firstly to call the folder directory where images is stored using the following command
> > >
> > > bandpath = 'C:\System\band files';
> > >
> > > then i specify the image i want using the following command
> > >
> > > bandFiles = dir(fullfile(bandpath, 'band2.JPG'));
> > >
> > > Then i'm stuck.
> > >
> > > what i'm trying to do next is to use if-else statement.
> > >
> > > where, if the 'band2.JPG' exist, the it will imshow('band2.JPG')
> > >
> > > else
> > >
> > > warndlg('No file recorded!!!','!! Warning !!');
> > > break;
> > >
> > > end
> > >
> > > the problem is that, i do not know how to write a code to justify that the band2.JPG
> > > exist. pls help. thanks

Subject: How to determine specific image is empty in a specific folder

From: Jan Simon

Date: 18 Feb, 2010 16:08:05

Message: 5 of 9

Dear Zulkifli!

> The thing is that in the folder not consist only one image. there are a few of them, how can determine which file i'm took?

> > > bandpath = 'C:\System\band files';
> > > bandFiles = dir(fullfile(bandpath, 'band2.JPG'));

With this command you took "band2.JPG", obviously.
So in general you determine it by the file name !?

Kind regards, Jan

Subject: How to determine specific image is empty in a specific folder

From: Dave Robinson

Date: 18 Feb, 2010 16:22:05

Message: 6 of 9

"Zulkifli " <zulkifliaziz@yahoo.com> wrote in message <hljmnq$933$1@fred.mathworks.com>...
> Hi all,
>
> I try to use isempty, but i won't work. What i'm trying to do firstly to call the folder directory where images is stored using the following command
>
> bandpath = 'C:\System\band files';
>
> then i specify the image i want using the following command
>
> bandFiles = dir(fullfile(bandpath, 'band2.JPG'));
>
> Then i'm stuck.
>
> what i'm trying to do next is to use if-else statement.
>
> where, if the 'band2.JPG' exist, the it will imshow('band2.JPG')
>
> else
>
> warndlg('No file recorded!!!','!! Warning !!');
> break;
>
> end
>
> the problem is that, i do not know how to write a code to justify that the band2.JPG
> exist. pls help. thanks

Something like
% Define the Path to the File
BandPath = 'C:\System\band files';

% Create the full Filename, including Directory
Filename = fullfile(bandpath, 'band2.JPG');

% Check if the file exists
if(EXIST(Filename,'file')
    % Yes it exists
    MyImage = imread(Filename);
   
    % Do things .....
else
    % No it doesn't exist
    warndlg('No file recorded!!!','!! Warning !!');
end

Warning I haven't tried this, but I believe something along these lines should give you what I understand you want

Regards

Dave Robinson
 

Subject: How to determine specific image is empty in a specific folder

From: ImageAnalyst

Date: 18 Feb, 2010 17:41:44

Message: 7 of 9

Allright, let's assume that you now have a valid filename, either by
specifying it exactly or by getting it from a list of a bunch of file
s that dir() returns. Now...what do you mean by the "image is
empty"? What exactly does that mean? The filename exists if you got
it from dir, and of course you can easily check that the file exists
with the exist(filename, 'file') command, and so you should be able to
read it in with imread(). Now, what is your definition of empty?
Does that mean a completely uniform image? Because I don't think
imread will return an empty object - it will either return the image
or throw an exception. So please define "image is empty."

Subject: How to determine specific image is empty in a specific folder

From: Zulkifli

Date: 19 Feb, 2010 01:27:04

Message: 8 of 9

Thank Dave Robinson,

It finally work. but it need some modification as below

bandPath = 'C:\System\band files';
Filename = fullfile(bandPath, 'band2.JPG');

if(exist(Filename,'file'))
MyImage = imread(Filename);
imshow(MyImage);
else
warndlg('No file recorded!!!','!! Warning !!');
end

I finally to define in the GUI, if i click a button for band2.JPG, it will show the image, else it will display warning dialog.

Thanks all




"Dave Robinson" <dave.robinson@somewhere.biz> wrote in message <hljpfd$a28$1@fred.mathworks.com>...
> "Zulkifli " <zulkifliaziz@yahoo.com> wrote in message <hljmnq$933$1@fred.mathworks.com>...
> > Hi all,
> >
> > I try to use isempty, but i won't work. What i'm trying to do firstly to call the folder directory where images is stored using the following command
> >
> > bandpath = 'C:\System\band files';
> >
> > then i specify the image i want using the following command
> >
> > bandFiles = dir(fullfile(bandpath, 'band2.JPG'));
> >
> > Then i'm stuck.
> >
> > what i'm trying to do next is to use if-else statement.
> >
> > where, if the 'band2.JPG' exist, the it will imshow('band2.JPG')
> >
> > else
> >
> > warndlg('No file recorded!!!','!! Warning !!');
> > break;
> >
> > end
> >
> > the problem is that, i do not know how to write a code to justify that the band2.JPG
> > exist. pls help. thanks
>
> Something like
> % Define the Path to the File
> BandPath = 'C:\System\band files';
>
> % Create the full Filename, including Directory
> Filename = fullfile(bandpath, 'band2.JPG');
>
> % Check if the file exists
> if(EXIST(Filename,'file')
> % Yes it exists
> MyImage = imread(Filename);
>
> % Do things .....
> else
> % No it doesn't exist
> warndlg('No file recorded!!!','!! Warning !!');
> end
>
> Warning I haven't tried this, but I believe something along these lines should give you what I understand you want
>
> Regards
>
> Dave Robinson
>

Subject: How to determine specific image is empty in a specific folder

From: ImageAnalyst

Date: 19 Feb, 2010 01:35:24

Message: 9 of 9

Perhaps you might be interested in this GUI tutorial:
http://www.mathworks.com/matlabcentral/fileexchange/24224
It pretty much does all of that. Reads image files into a listbox,
where you can click and display it. Also has button for selecting a
folder, plus various other controls (checkboxes, etc.)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us