CONFOCALMICROSCOPY Archives

December 2012

CONFOCALMICROSCOPY@LISTS.UMN.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Ronan Chéreau <[log in to unmask]>
Reply To:
Confocal Microscopy List <[log in to unmask]>
Date:
Fri, 21 Dec 2012 05:34:50 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (127 lines)
*****
To join, leave or search the confocal microscopy listserv, go to:
http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
*****

Hi fellows,

Following the post on smart average
(http://labrigger.com/blog/?s=smart+average), I propose another way to
perform a projection of a z-stack that does not involve any thresolding or
any filtering.
As when you select the brightest pixel of the z-serie to obtain a maximum
projection, my idea is to look for the z-plane from which the brightest
pixel was taken and then average this pixel with the ones from the plane
before and after.
As a result, stochastic noise is greatly reduced and the real signal is
consolidated knowing that it's always contained in more than one plane.

I think some could be interested in this.
regards

Ronan Chéreau

Here is the matlab code to perform the projection (2 functions: 1 to do the
projection and 1 that is used by the first one to import a imagej like tiff
stack):



function result=smartass_projection(tiffstack,name_result,bin)


%%%% Ronan Chéreau %%%%% 121030 %%%%
%Do a max projection but special.
%Look for the max pixel thru the stack + take the pix before and after in
the z-dimension and
%average them to give the final image

%INPUTS: tiffstack     name of the tiff stack
%        name_result   specify a name for the smartass projection image
%        bin           number of pixels to bin around zmax (1 makes an
average of 3 pixels)

%REQUIRES: being in the directory that contains the tiff stack
%          import_tiffstack.m

if nargin==2, bin=1; end
if nargin==3, end

nb_frames=size(tiffstack,3);

max_proj=zeros(size(tiffstack,1),size(tiffstack,2));
numero=zeros(size(tiffstack,1),size(tiffstack,2));
result=zeros(size(tiffstack,1),size(tiffstack,2));


%Does a max projection
for x=1:size(tiffstack,1);
    for y=1:size(tiffstack,2);
        max_proj(x,y)=max(tiffstack(x,y,1:nb_frames));
    end
end

%Finds the image from which the max pixel is coming from and stores it in
%numero.
for x=1:size(tiffstack,1);
    for y=1:size(tiffstack,2);
        for z=1:nb_frames;
                if tiffstack(x,y,z)==max_proj(x,y),
                    numero(x,y)=z;
                end
        end
    end
end

%Does the smartass projection: for every x,y position on the stack, it
%goes to the z-plane that has the max intensity and average it with the pixel
%from the plane before and the plane after.
for x=1:size(tiffstack,1);
    for y=1:size(tiffstack,2);
        if numero(x,y)<bin+1,
           
result(x,y)=sum(tiffstack(x,y,numero(x,y))+tiffstack(x,y,numero(x,y)+1));
        elseif numero(x,y)>nb_frames-bin,
           
result(x,y)=sum(tiffstack(x,y,numero(x,y)-1)+tiffstack(x,y,numero(x,y)));
        else
        result(x,y)=sum(tiffstack(x,y,numero(x,y)-bin:numero(x,y)+bin));
        end
    end

end

%8 or 16 bit result
maxpix=max(result(:));

if maxpix>255,
    result=uint16(result);
else
    result=uint8(result);
end

imwrite(result,name_result,'tif');






function FinalImage=import_tiffstack(FileTif)
%from "http://www.matlabtips.com/how-to-load-tiff-stacks-fast-really-fast/"

%Imports a tiff stack.
%requirement: be in the directory
InfoImage=imfinfo(FileTif);
mImage=InfoImage(1).Width;
nImage=InfoImage(1).Height;
NumberImages=length(InfoImage);
FinalImage=zeros(nImage,mImage,NumberImages,'uint16');
 
TifLink = Tiff(FileTif, 'r');
for i=1:NumberImages
   TifLink.setDirectory(i);
   FinalImage(:,:,i)=TifLink.read();
end
TifLink.close();

ATOM RSS1 RSS2