Time-optimization? Digital image processing
Show older comments
Hello,
For each column of the mask, I calculate the first non-zero pixel position (2000 images). Then, I save them to an array and compute the maximum; between other simple operations.
It is working fine, but it is not at all time-efficient. Would you have any suggestion?
Thank you very much,
Best regards,
Santiago
Base= Mask;
i=1;
b= zeros (y,1,num_images,'double'); %preallocating
rows= x;
columns= y;
for k= 1:num_images;
for col= 1: columns
a = find(D(:, col,k), 1, 'first'); %find the first non-zero pixel
if a > 0
b(i,k) = a;
c = max (b(:,k));
i= i+1;
else
continue
end
end
Base(c:rows,:,k)=1; %keeping the top part
end

Accepted Answer
More Answers (1)
Image Analyst
on 3 Jan 2017
Edited: Image Analyst
on 3 Jan 2017
It looks like you're finding the lowest of the top-most pixels in each image and then setting Base array from that row downwards to 1. Well you don't have to do that setting of the Base matrix for each and every column. It can be done once, after the col loop ends. Inifialize c to -inf inside the k loop but before the col loop starts.
c = -inf;
Then set c like this:
c = max ([c ; b(:,k))];
Also, you should use
if ~isempty(a)
rather than
if a > 0
Categories
Find more on Creating and Concatenating Matrices 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!