MATLAB Answers

Reading and process many images (Median Filter)

2 views (last 30 days)
Chew
Chew on 12 Aug 2020
Answered: Srivardhan Gadila on 19 Aug 2020
I am currently writing a code for median filter, but I am only able to read 1 image by 1 image.
Is there a way to load in 30 images and process the data instantly?
I have a function to read single image for my median filter, I have another code to load 30 images to process.
But I have no idea how to combine two codes together.
The median filter code :
function f=asmf(n_Img)
[m n]=size(n_Img);
a=n_Img;
fl(1:m,1:n)=1;
mw=5;
for i=1:m
for j=1:n
cond=1;
xw=1;
while(cond==1)
co=0;
for k=-xw:xw
for l=-xw:xw
if (((i+k >0)&&(i+k<=m))&&(j+l >0))&&(j+l<=n)
co=co+1;
s(co)=a(i+k,j+l);
end
end
end
min1=min(s);
min2=max(s);
if (a(i,j)>min1)&&(a(i,j)<min2)
fl(i,j)=0;
cond=0;
else
if xw>=mw
cond=0;
else
xw=xw+1;
end
end
clear s;
end
end
end
wcm=16;
td=5;
for i=1:m
for j=1:n
if fl(i,j)==0
f(i,j)=a(i,j);
else
cond=1;
xw=1;
while (cond==1)
co=0;
for k=-xw:xw
for l=-xw:xw
if (((i+k >0)&(i+k<=m))&(j+l >0))&(j+l<=n)
if fl(i+k,j+l)==0
co=co+1;
s(co)=a(i+k,j+l);
end
end
end
end
if (co>0)
if (abs(a(i,j)-min(s))<td)&&(abs(a(i,j)-max(s))<td)
f(i,j)=a(i,j);
else
f(i,j)=median(s);
end
cond=0;
elseif (xw>=wcm)
f(i,j)=a(i,j);
cond=0;
else
xw=xw+1;
end
clear s;
end
end
end
end
The code for loading the images:
FileName = [
"img01.tiff";
"img02.tiff";
"img03.tiff";
"img04.tiff";
"img05.tiff";
"img06.tiff";
"img07.tiff";
"img08.tiff";
"img09.tiff";
"img10.tiff";
"img11.tiff";
"img12.tiff";
"img13.tiff";
"img14.tiff";
"img15.tiff";
"img16.tiff";
"img17.tiff";
"img18.tiff";
"img19.tiff";
"img20.tiff";
"img21.tiff";
"img22.tiff";
"img23.tiff";
"img24.tiff";
"img25.tiff";
"img26.tiff";
"img27.tiff";
"img28.tiff";
"img29.tiff";
"img30.tiff";
];
for imagefile = 1:1;
for noiselevel = 0:99;
imagefile
noiselevel
n_Img = imread(convertStringsToChars(FileName(imagefile)));
Thanks for the help!

  0 Comments

Sign in to comment.

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 19 Aug 2020
Based on the above information & as per my knowledge, one suggestion would be to make use of parfor instead of regular for loop. You can replace the for loop where you load the images and process them through your function with parfor loop, In that way based on the number of workers of parallel pool you can process those many images in parallel.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!