Got Questions? Get Answers.
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:
Reading a sequence of images with complex filenames

Subject: Reading a sequence of images with complex filenames

From: James

Date: 4 Dec, 2009 12:07:06

Message: 1 of 5

Hi everyone,

I'm trying to use imread to read in a series of bmps for processing, that are in a format like so:

_0000(z=0.010).bmp
_0001(z=0.178).bmp
_0002(z=0.267).bmp
_0003(z=0.301).bmp
...etc.

It's the first bit of the filename (0001, etc) that defines the order of the bmps, the second bit(z=#.###) is causing me trouble. There is no guarantee that the number increases by the same amount each time. Basically, I just want to specify the order of the bmps by the first bit of the file and ignore the rest (except the information that tells imread it's an image, which I assume is the '.bmp'). I've got this:

for i=1:9
   image = imread(['_000',num2str(i-1),'(z=*.***).bmp']);
end

...where I'm hoping that some kind of * wildcard exists! Obviously, this doesn't work, but it illustrates what I want. Any help would be greatly appreciated!

Subject: Reading a sequence of images with complex filenames

From: James

Date: 4 Dec, 2009 12:12:05

Message: 2 of 5

Sorry, I didn't mean to post this twice!

Subject: Reading a sequence of images with complex filenames

From: Branko

Date: 4 Dec, 2009 12:17:13

Message: 3 of 5

"James " <mmjpjb2@lboro.ac.uk> wrote in message <hfau1a$lbr$1@fred.mathworks.com>...
> Hi everyone,
>
> I'm trying to use imread to read in a series of bmps for processing, that are in a format like so:
>
> _0000(z=0.010).bmp
> _0001(z=0.178).bmp
> _0002(z=0.267).bmp
> _0003(z=0.301).bmp
> ...etc.
>
> It's the first bit of the filename (0001, etc) that defines the order of the bmps, the second bit(z=#.###) is causing me trouble. There is no guarantee that the number increases by the same amount each time. Basically, I just want to specify the order of the bmps by the first bit of the file and ignore the rest (except the information that tells imread it's an image, which I assume is the '.bmp'). I've got this:
>
> for i=1:9
> image = imread(['_000',num2str(i-1),'(z=*.***).bmp']);
> end
>
> ...where I'm hoping that some kind of * wildcard exists! Obviously, this doesn't work, but it illustrates what I want. Any help would be greatly appreciated!

One possible solution would be, use of dir (i.e. flist=dir('*.bmp')) and then use imread (for loop) to read images.

Branko

Subject: Reading a sequence of images with complex filenames

From: Rune Allnor

Date: 4 Dec, 2009 12:38:07

Message: 4 of 5

On 4 Des, 13:17, "Branko " <boguno...@mbss.org> wrote:
> "James " <mmjp...@lboro.ac.uk> wrote in message <hfau1a$lb...@fred.mathworks.com>...
> > Hi everyone,
>
> > I'm trying to use imread to read in a series of bmps for processing, that are in a format like so:
>
> > _0000(z=0.010).bmp
> > _0001(z=0.178).bmp
> > _0002(z=0.267).bmp
> > _0003(z=0.301).bmp
> > ...etc.
>
> > It's the first bit of the filename (0001, etc) that defines the order of the bmps, the second bit(z=#.###) is causing me trouble. There is no guarantee that the number increases by the same amount each time. Basically, I just want to specify the order of the bmps by the first bit of the file and ignore the rest (except the information that tells imread it's an image, which I assume is the '.bmp'). I've got this:
>
> > for i=1:9
> >    image = imread(['_000',num2str(i-1),'(z=*.***).bmp']);
> > end
>
> > ...where I'm hoping that some kind of * wildcard exists! Obviously, this doesn't work, but it illustrates what I want. Any help would be greatly appreciated!
>
> One possible solution would be, use of dir (i.e. flist=dir('*.bmp')) and then use imread  (for loop) to read images.

If you also add a regular expression to verify that
the file name follows the indicated pattern (and even
to extract the ordinal from the file name), you ought
to be there.

Rune

Subject: Reading a sequence of images with complex filenames

From: James

Date: 4 Dec, 2009 14:30:30

Message: 5 of 5

Rune Allnor <allnor@tele.ntnu.no> wrote in message <4acc5542-0cf5-42c2-82ed-c8b7239698aa@m38g2000yqd.googlegroups.com>...
> On 4 Des, 13:17, "Branko " <boguno...@mbss.org> wrote:
> > "James " <mmjp...@lboro.ac.uk> wrote in message <hfau1a$lb...@fred.mathworks.com>...
> > > Hi everyone,
> >
> > > I'm trying to use imread to read in a series of bmps for processing, that are in a format like so:
> >
> > > _0000(z=0.010).bmp
> > > _0001(z=0.178).bmp
> > > _0002(z=0.267).bmp
> > > _0003(z=0.301).bmp
> > > ...etc.
> >
> > > It's the first bit of the filename (0001, etc) that defines the order of the bmps, the second bit(z=#.###) is causing me trouble. There is no guarantee that the number increases by the same amount each time. Basically, I just want to specify the order of the bmps by the first bit of the file and ignore the rest (except the information that tells imread it's an image, which I assume is the '.bmp'). I've got this:
> >
> > > for i=1:9
> > > ? ?image = imread(['_000',num2str(i-1),'(z=*.***).bmp']);
> > > end
> >
> > > ...where I'm hoping that some kind of * wildcard exists! Obviously, this doesn't work, but it illustrates what I want. Any help would be greatly appreciated!
> >
> > One possible solution would be, use of dir (i.e. flist=dir('*.bmp')) and then use imread ?(for loop) to read images.
>
> If you also add a regular expression to verify that
> the file name follows the indicated pattern (and even
> to extract the ordinal from the file name), you ought
> to be there.
>
> Rune

Branko, Rune
Thanks for your help. With your suggestions and help from a colleague it works!

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