Efficient Coding to save run time
Show older comments
I have a three dimensional cell that holds images (i.e. images = cell(10,4,5)) and each cell block holds images of different sizes. The sizes are not too important in terms of what I’m trying to achieve. I would like to know if there is an efficient way to compute the sharpness of each of these cell blocks (total cell blocks = 10*4*5 = 200). I need to compute the sharpness of each block using the following function:
If it matters:
- 40 cell blocks contain images of size 240 X 320
- 40 cell blocks contain images of size 120 X 160
- 40 cell blocks contain images of size 60 X 80
- 40 cell blocks contain images of size 30 X 40
- 40 cell blocks contain images of size 15 X 20
which totals to 200 cells.
%%Sharpness Estimation From Image Gradients
% Estimate sharpness using the gradient magnitude.
% sum of all gradient norms / number of pixels give us the sharpness
% metric.
function [sharpness]=get_sharpness(G)
[Gx, Gy]=gradient(double(G));
S=sqrt(Gx.*Gx+Gy.*Gy);
sharpness=sum(sum(S))./(480*640);
Currently I am doing the following:
sharpness = size(images);
for i = 1 : 10
for j = 1 : 4
for k = 1 : 5
sharpness(i,j,k) = get_sharpness(images{i,j,k});
end
end
end
The sharpness function isn’t anything fancy. I just have a lot of data hence it takes a long time to compute everything.
Currently I am using a nested for loop that iterates through each cell block. Hope someone can help me find a better solution.
(P.S. This is my first time asking a question hence if anything is unclear please ask further questions. THANK YOU)
Answers (1)
Andrei Bobrov
on 22 Jun 2016
sharpness = zeros(size(images));
for ii = 1 : 10
for jj = 1 : 4
for k = 1 : 5
sharpness(ii,jj,k) = get_sharpness(images{ii,jj,k});
end
end
end
1 Comment
Jigar Patel
on 22 Jun 2016
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!