Simple Image Processing Optimisation
Show older comments
I have a simple image processing application that is working fine, but I think it could be vectorised and sped up substantially. I've had a shot but am having trouble with it.
The idea is to take a series of images and get
- timex: time exposure (the average of each pixel over time)
- immax: each pixel with the maximum intensity over time
- immix: each pixel with the minimum intensity over time
Working code:
im_stack=[timestep,x_pixel,y_pixel,[red,green,blue,intensity]]
timex = nan(x,y,3); immax = timex; immin = timex; %preallocate
for i = 1:x
for j = 1:y
for k = 1:z
timex(i,j,k)= mean(im_stack(:,i,j,k));
end
[~,a] = max(im_stack(:,i,j,4));%from intensity values
immax(i,j,1:3)= im_stack(a,i,j,1:3);
[~,a] = min(im_stack(:,i,j,4));
immin(i,j,1:3)= im_stack(a,i,j,1:3);
end
end
timex=uint8(timex);
immax=uint8(immax);
immin=uint8(immin);
3 Comments
Walter Roberson
on 9 Jul 2016
Could you clarify what is special about im_stack(:,:,:,4) compared to im_stack(:,:,:,1:3) ? And what values is z ?
Ben Modra
on 9 Jul 2016
Ben Modra
on 14 Jul 2016
Answers (1)
Walter Roberson
on 9 Jul 2016
As a start:
With no loops needed,
timex = squeeze( mean(im_stack(:,:,:,1:z)) );
And if z is the same as size(im_stack,4) then it would simplify to
timex = squeeze( mean(im_stack) );
Categories
Find more on Programming 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!