any ideas how to make the code more efficient? Now it takes a few days!
Show older comments
I have 200 images and I am trying to calculate Signal to Noise ratio at each pixel following the formula
SNR at each pixel = mean(pixel (x,y) value from 200 image)/std(pixel (x,y) value from 200 image).
It takes ages to process the images using the code bellow even on super powerful computer. Any ideas as to how to speed up the code are very much appreciated.
% Reading multiple image files test1_0001.edf to test1_0200.edf in a loop
for i=1:200
if i<100
filename=strcat('test1_00',num2str(i),'.edf');
[header matrix]=pmedf_read(filename);
variablename=strcat('test1_00',num2str(i));
eval([variablename '=matrix;']);
else
filename=strcat('test1_0',num2str(i),'.edf');
[header matrix]=pmedf_read(filename);
variablename=strcat('test1_0',num2str(i));
eval([variablename '=matrix;']);
end
end
% Getting mean count per pixel from all images
x=2500;
y=1500;
for r=1:x % rows
for c=1:y % columns
for i=1:200
if i<100
pixel_image(i)=eval(strcat('test1_00',num2str(i),'(r,c)'));
else
signal_value(i)=eval(strcat('test1_0',num2str(i),'(r,c)'));
end
signal_pixel(r,c)=sum(signal_value(:))/200;
std_pixel(r,c)=std(signal_value(:));
snr_pixel(r,c)=signal_pixel(r,c)/std_pixel(r,c);
end
end
end
2 Comments
Di you profile the code to find the bottleneck(s)? You are doing several operations that can be slow (reading files, using EVAL, etc), and it would be relevant to know how they compare in term of execution time.
If you didn't profile it yet, modify your script so it treats e.g. 5 files instead of 200, then type the following in the command line:
profile viewer
In the field, type the name of your script and click on [Start profiling]. Then study the report.
Accepted Answer
More Answers (1)
Walter Roberson
on 19 Apr 2013
0 votes
The eval() are slowing you down.
Categories
Find more on Object Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!