Skip to content

This project contains the functions used for creating raw and refined masks, and for adjusting images using CLAHE.

Notifications You must be signed in to change notification settings

KinneretLab/DisplayFunctions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Updated August 2021

Part I - Creating masks

Data saving location:

'Your movie analysis folder''specific movie folder'\Display\

To perform analysis only on desired region of images, we create binary masks for each image. The default is to exclude the area outside the tissue (where there is no fluorescent signal), and the outer edge of the tissue, where there are strong fluorescence gradients that cause artefacts in orientation analysis. However, if you are interested only in a specific region of the tissue, you can manually create a mask accordingly.

When automaically creating the masks for the analysis region, we generate masks that exclude the area outside the tissue (and areas where the image quality is very low). These masks are saved in the main movie folder, under “Display/Masks” . Since for the orientation analysis we also want to exclude the edges of the tissue, we perform an additional erosion of the mask from the boundary, and use the resulting smaller mask within the orientation analysis. The orientation and coherence fields are saved only within this smaller masked area.

Notice: The automaic thresholding and post-processing for creating the masks is based on the Lifeact-GFP images. Imaging of other channels will require different thresholding and processing.

We use a slightly different process to generate masks for the data from the spinning-disk and lightsheet microscopes. Sometimes, the process used for the lightsheet might also give better results for the spinning-disk data, so if the masks used for spinning-disk data are not satisfactory, it’s worth trying the lightsheet version as well.

Masks are automatically generated in two steps, starting from either single plane projected images (option 1A) or image stacks (option 1B):

1. ImageJ macro to generate raw masks:

Option 1A: “make_raw_mask” / “make_raw_mask_lightsheet” Option 1B: “make_raw_mask_from_stack” / “make_raw_mask_from_stack_lightsheet”/ “make_raw_mask_from_stack_endo”

If starting from image stacks, the macro first creates a maximum intensity projection image of the image stack (not saved, just open locally). Then, on the single plane images (whether these are the input images or the locally created projections), the macro performs the initial thresholding of the raw images (found typically either in “Orientation_Analysis/Raw Images”, or in the original location of the image stacks) and produces masks (8-bit tiff), which are saved under “Display /RawMasks”. The reason this is done in ImageJ and not in matlab is that ImageJ has a larger choice of inbuilt thresholding algorithms. The method used here for thresholding is the “Li” method.

Difference between spinning-disk and lightsheet masks: For the lightsheet data, the masks undergo additional processing within the imageJ macro, to close and smooth the surface of the mask. For the spinning-disk data, slightly different steps are performed later in the matlab function instead of the imageJ macro. For the life-act GFP endoderm images (from the spinning disk), the process is similar to the lightsheet, but parameters are adapted to suit these images.

In all cases there are two options for running over multiple folders: The first is to run over all subfolders within a directory "topdir" , the second is to run over all folders listed manually in "dirlist". The relevant option should be uncommented, and the unused option should remain as a comment.

Option 1: Run over all subfolders in top directory.

Option 2: List subfolders manually. You will still need to enter the directories under “dirlist”, and the names should only contain the ending that is distinct from subfolder to subfolder (and not the top directory).

2. Processing raw masks in matlab

The second step is further processing of the raw mask in matlab, either through the main function “runCreateTotalMask” (which runs variations of the function createTotalMask according to data type), or automatically if running as part of the orientation analysis (in that case, you can skip directly to the orientation analysis).

The processing involves steps of filling holes, and iterative erosion and dilation to smooth the edges of the mask and modify it to most accurately match the true tissue outline. The mask is then further smoothed by convolving with a gaussian kernel and selecting the isosurface of I=0.5. All lengh scales in the smoothing are given in terms of “blocksigma” (see orientation analysis manual).

** In the case of the lightsheet data and endo data, the function “CreateTotalMask_lightsheet” only performs the final smoothing step.

If running as part of the orientation analysis:

Make sure to set the parameter “isLS” to zero for spinning-disk raw masks and 1 for lightsheet raw masks.

The total masks will be created automatically - within the orientation analysis, when running over each movie in the main analysis directory, the first step before analysing the orientation field is creating the total area masks from the raw masks. This is done by a matlab function called “CreateTotalMask”, which recieves all its argument through the main runMovieAnalysis function.

If running independently:

Run the matlab function “runCreateTotalMask”, which will loop over all movies according to the same folder structure as the main orientation analysis function:

%% define mainDirList
topMainDir='\\phhydra\phhydraB\Analysis\users\Yonit\Movie_Analysis\Anton\'; % main folder for movie analysis
mainDirList= { ... % enter in the following line all the all the movie dirs to be analyzed
% 'Test_2_images', ...
 
 'hyd256\hyd256_pos21\', ...
 'hyd256\hyd256_pos10\', ...
};

Parameters to set:

toSave=1; % If zero, doesn't save images and doesn't overwrite existing images.
IsLS=0; %1 for Lightsheet or Endo, 0 otherwise
IsLabel = 0; %1 for tissue label, 0 otherwise
calibration = 1.28; % In um/pixel. 1.28 um/pixel for 10x air.
% Comment out if not necessary:
framesList = {1:6,1:9}; Enter specific frame ranges in this format if you
% want to run on particular frames (in this example, 1:6 is for the first
% movie, 1:9 is for the second). If left empty, runs on all frames.

In all cases, the resulting masks are binary images with values 0 or 1 (saved as 8-bit tiff), under the folder “Orientation_Analysis /Masks”.

** If you are not working as part of the orientation analysis process, the raw masks and total masks should be saved under your main analysis directory, under a folder named “Display”. If working within the orientation analysis process, the total masks are saved in the display folder, and automatically copied to the orientation analysis folder when you run the Orientation Display functions. There is also an option in the orientation analysis pipeline to use masks generated independently, if they are saved in the orientation analysis folder.

Part II - Image adjustment using CLAHE

Adjusting images using adaptive histogram filter “adapthisteq” in matlab (CLAHE filter).

Main function: “runAdjustImages”

Input:

Folder structure as in all other analysis:

topMainDir='\\phhydra\phhydraB\Analysis\users\Yonit\Movie_Analysis\Anton\'; % main folder for movie analysis
mainDirList= { ... % enter in the following line all the all the movie dirs to be analyzed
% 'Test_2_images', ...
 
'ForFigure\hyd256pos21\',...
 
};

Calibration:

calibrationXY = 1.28; % um/pixel for 10x air lens
% calibrationXY = 0.57; % um/pixel for lightsheet
% calibrationXY = 0.65; % um/pixel for 20x lens

Specific input and output folder names within the main analysis directory of the movies (notice difference if you are running on images of fibres or cortices for example):

% inputFolderName = 'Orientation_Analysis\Raw Images';
% outputFolderName = 'Orientation_Analysis\AdjustedImages';

 inputFolderName = 'Cells\Raw Cortices';
 outputFolderName = 'Cells\Adjusted_cortices';

saveFormat = 2; % Choose 1 for PNG, 2 for TIFF
sigma = 0; % Kernel size for gaussian blur, set to zero if no blur needed.
saveStretched = 0; % Set to 1 if you want to save the images separately with stretched histograms (relevant mostly for images from SD2).

The option for gaussian blurring can be useful for images of tissue labels. The option to save images with stretched histograms is useful especially for images from the Up&Under spinning disk microscope, which typically produces images that do not use the full image bit depth, and therefore need stretching if we are to run processes on them that were built with the images from the older spinning-disk (mostly CARE, segmentation, final image inference).

The main function runs on all images in the input folder, and for each image runs the function “adjustImages” where the adjustment happens. Default parameters are set within the function, so far no changes have been found to lead to better results.

About

This project contains the functions used for creating raw and refined masks, and for adjusting images using CLAHE.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published