From: Steven Lord on

"Krzysztof" <kprzychodzki(a)gmail.com> wrote in message
news:db1ab3d3-8f8b-4955-9119-47482e6731d1(a)j19g2000yqk.googlegroups.com...
> On Oct 14, 12:29 am, ImageAnalyst <imageanal...(a)mailinator.com> wrote:
> > On Oct 13, 3:38 pm, Krzysztof <kprzychod...(a)gmail.com> wrote:> %but here
> > I don't know what to type, to use medfilt2 function for each
> > > photo, and save to file.
> >
> > ----------------------------------------
> > Is there something about the documentation for medfilt2, imread, and
> > imwrite that is confusing you???? It seems rather straightforward.
> > You pass in an array, and filename (if needed), and it does its
> > thing. Can you really not understand it?
>
>
> Yes I can't understand it. You have expirience in matlab, as you wrote
> in your profile, so this is simple for you. but for me it is not.
>
> I write something like that:

If you're asking for help, posting code that's "something like" what you're
using is of limited or no help. Post EXACTLY the code you're using.

> f = dir('path to files/*.tif');
>
> for i = 1:10

Is there a particular reason you only want to process the first ten files?
Replace this line with:

for k = 1:numel(f)

and replace the next line:

> filename = f(i).name;

filename = f(k).name;

That way there's no chance of interacting with the built-in function i.

> data = imread(filename);
> data2 = medfilt2(data, [5 5]);
> imwrite(data2, filename);
> end

Other than that, the syntax looks generally correct.

> but still I have problem with writing files, because this script made
> one file, and every calculations of medfilt2 write to that one file.
> And I want to do new 2000 files or to overwrite existing once.

Unless you've somehow replicated one or more of the entries in the struct
DIR returned in the variable f, it shouldn't be overwriting. Try this --
don't overwrite the file, but instead make a new copy with a slightly
different name, and confirm whether or not the script is overwriting the
same file name each time.


f = dir('<fill this in');
for k = 1:numel(f)
filename = f(k).name;
data = imread(filename);
data2 = medfilt2(data, [5 5]);
imwrite(data2, ['M' filename]);
end


You should, after this is executed, have two files for each image you read
in; their names should differ only in the fact that one starts with M and
the other does not.

If this doesn't work, post EXACTLY the code you've tried and exactly what
happened (did the code only create one file whose name started with M, did
it throw an error [and if so what was the full text of the error message],
etc.) You may also want to try removing the semicolon from the line of code
in the FOR loop that creates the variable filename and make sure it's using
the file name you expect at each iteration.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Krzysztof on
Ok.
I explain what I need and want to obtain.

I have 2000 tiff files, and I have to use medfilt2 function for each
one of these files. And write result to another (or overwrite) 2000
files.
It's sound simple, 3 steps:

for 1 to 2000 do this:

1. Find file on hard drive, and read image in matlab
2. use medfilt2 function to this file
3. save result to new file, or overwrite existing one

end

In result of that script I shall have another folder with new 2000
files after medfilt. With names the same like originalas.

I know it is simple, but I don't use matlab every day, (I work in
SolidWorks, Autocad), but I have to do this.