Welcome to the web page 
of Peter Nagy

Experience and experiments with Matlab

What a "user-friendly" application! This was my first impression when I first installed Matlab on my computer and it started up with a screen with a command prompt and basically nothing else. But I gradually began to appreciate the flexibility and power of data analysis and the relative ease of programming of Matlab. I wrote Matlab code for fun and for developing applications for myself or for my colleagues. Below, you can find  a selection of the image analysis utilities I developed.

openpicture: a GUI-based application to open images

The program is a simple application for opening images supported by the "bfopen" command of the BioFormats package in Matlab. Therefore, BioFormats must be installed. Since DipImage is the default output image type, DipImage must also be installed.

Syntax:

  • openpicture (i.e. simply type "openpicture" at the Matlab command prompt). Three GUIs will be displayed consecutively. First, the user must decide if the images are exported into a DipImage image type or numeric array. Then, the user must select which image file to open. Lastly, if the image is a 3D stack, the user must decide if the images are to be exported into the Matlab environment as a stack or as single images.
  • openpicture(fullPathToImage, outputType) - the image which can be found at the location specified by the first input parameter (fullPathToImage) will be read. outputType can be 'dipimage' or 'numeric'. A GUI will be displayed to specify the output image and its type as explained above. If "outputType" is not specified, the type of the output will be DipImage.
  • imageOut=openpicture(fullPathToImage, outputType) - the same as above, but a GUI is not displayed for specifying the output. Instead, the output image will be "imageOut". If the image is 3D, the output will be a 3D stack.
  • imageOut=openpicture - the input will be specified by GUIs, but the output will be saved into the variable specified by the output argument of the function

Download: openpicture.p

Upgrades: At every run of the program it automatically checks for available upgrades and warns the user to press the "Upgrade" button to perform the process.

Draw regions of interests (ROI) in an image: imagegate

Another simple application. You draw a region on interest (ROI) on to an image with a color specified in the GUI. There are two kinds of outputs:

This is how to draw the ROI:

Syntax: type 'imagegate' at the Matlab command prompt
Without input arguments the application will be started in GUI-mode.
If input arguments are given, the GUI won't be shown. Example for syntax when input arguments are present: imagegate(imageToDrawOn,'linecol','b','closeline',1,'timesdilate',0,'roitype',1/2,'radius',2)

Download: imagegate.p

The application checks for updates after it is started.

Analysis of regions of interest in images

  • The program analyzes regions of interest (ROI) in a series of images.
  • The ROIs are defined in a mask image as noncontiguous regions, which will be analyzed separately. 
  • You can provide one single such mask image that will be used for all the images, or you can provide a mask corresponding to every single image.
  • Images to be analyzed and the mask images can be provided as MATLAB variables or as paths to files. Images and masks are read by the 'openpicture' program available on this page.
  • The program's name is 'simpleCellAnalyzer2'. It can be run interactively when run without input arguments, i.e., type 'simpleCellAnalyzer2' at the MATLAB command prompt. The GUI is shown on the left.
  • With input parameters, the following command-line syntaxes are possible:
    [results,roi_image]=simpleCellAnalyzer2('onemask',images,mask);
    One mask is used for analyzing all the images. The images are either provided as a list of MATLAB variables, or as a single cell array of file names. The mask can also be specified as a MATLAB variable or as a file name.[results,roi_image]=simpleCellAnalyzer2('manymasks',images,masks);
    A different mask will be used for analyzing every image. The number of masks and images have to be identical. Just as in the 'onemask' case, both the images and the masks can be specified as MATLAB variables or as file names.
    Output parameters:
    results - a table with the output results
    roi_image - a labeled image with the ROIs
    A representative table output is shown below. ObjectID "Inf" corresponds to the evaluation of the union of ROIs. "pixels" contain the intensities of pixels that constitute the ROI.
  • A couple of examples for running the program with input parameters:
    simpleCellAnalyzer2('onemask',{'i1.tif','i2.tif'},{'m1.tif'})
    simpleCellAnalyzer2('onemask',{'i1.tif','i2.tif'},m1)
    simpleCellAnalyzer2('onemask',i1,i2,m1)
    simpleCellAnalyzer2('onemask',i1,i2,{'m1.tif'})
    simpleCellAnalyzer2('manymasks',{'i1.tif','i2.tif'},{'m1.tif','m2.tif'})
    simpleCellAnalyzer2('manymasks',{'i1.tif','i2.tif'},m1,m2)
    simpleCellAnalyzer2('manymasks',i1,i2,m1,m2)
    simpleCellAnalyzer2('manymasks',i1,i2,{'m1.tif','m2.tif'})
  • When run without input arguments, the program searches for the availability of a newer version.
  • Download the simpleCellAnalyzer2 file.

Preprocess a series of images using a custom-written code

  • The program processes a series of images according to a MATLAB code specified in the code window. The principle of the program is similar to the functionality of ImageJ or FIJI available at Process>Batch>Macro.
  • Start the program by typing "batchPreProcesss" at the MATLAB command prompt.
  • You can choose two different sets of images (first input and second input) to be processed. Providing a second set of images is optional. Both of them can be specified either as a folder (every file in the folder will be processed) or as a cell array variable in which MATLAB variables are specified, e.g., {‘a’,’b’,’c’} will instruct the program to process images stored in variables ‘a’, ‘b’ and ‘c’. The output can be saved into a folder or as a structure variable into the MATLAB workspace. 
  • You can type or paste the code in the window, or load it by pressing the “Load code” button. The code can be saved by pressing the “Save code” button.
  • Press the “Process” button and the images will be processed according to the code.
  • The program automatically checks for upgrades.
  • More detailed help, also available from within the program.
  • Download the program. This is a ZIP file containing the program and the HTML help. Unzip them into the same folder.

Evaluation of a mask in an image (mask_evaluate)

A very simple application. A grey-scale image is analyzed in pixels defined by another image called the mask. Only those pixels of the first image (grey-scale image) are analyzed which are "1" in the mask. After pressing 'Analyze' the following parameters are calculated:

You can save the results to a text file or export the results into Matlab variables.

You can use the "imagegate" application, available in this page, to create the mask image.

Syntax: mask_evaluate

Download: mask_evaluate.p

The application checks for updates after it is started.

Manaully-seeded (marker-controlled) watershed segmentation (watershed_segment)

Manually-seeded watershed transformation implemented in Matlab using DipImage functions.

Syntax and help:
[output_type_1,output_type_2]=watershed_segment(image,output_type,connectivity)
OR
[output_type_1,output_type_2]=watershed_segment, i.e. without any input argument.

Output arguments are optional.

Input arguments:

Click on center of cell. Don't forget to mark the background too. SHIFT-click or double-click to exit any time. You can delete regions by CTRL-clicking on a dot. If you aren't satisfied with the result, you can modify the position of each dot. At this stage you can't delete or add any region. You can do this by answering yes to the "More or fewer cells" question at the end.

Download: watershed_segment.p

The application checks for updates after it is started.

Manually-seeded (marker-controlled) watershed segmentation in 3D

The application performs manully-seeded or marker-controlled watershed segmentation in a 3D image stack. An orthogonal view of the 3D stack is shown, and the user places seeds in an arbitrary slice chosen by the mouse scroll wheel.  The result of the watershed segmentation is shown, and the user can merge regions or swap their label.

The program can be run in GUI-mode or command-prompt-mode. Type 'watershed_segment3d' at the Matlab command prompt and a GUI, shown on the left below, will be displayed. If you would like to prevent the program from checking for upgrades, type watershed_segment3d('noupdate'). Alternatively, you can use the following command prompt syntax:
[segmentedImage,seedPos]=watershed_segment3d(imageIn,seeds,circleRadius,circleColor,aspectRatio,minArea,outputType)

The program requires DipImage that can be downloaded from here.

Download: watershed_segment3d.p

The program checks for updates after it is started in GUI-mode.

Graphical user interface of the program

Membranes (boundaries) overlaid on the gray-scale stack shown during the segmentation.

Result of the segmentation: orthogonal view of the cells and the membranes (red)

Dijkstra-Nagy algorithm for image segmentation

Some images are notoriously complicated regarding segmentation. Dijkstra's algorithm is an approach to find the shortest path between nodes in a graph. I have modified this algorithm to find the path with the highest mean intensity between two pixels in an image. I took the liberty to call it Dijkstra-Nagy algorithm which works nicely to find the cell membrane.

The program is GUI-controlled. The user is asked to provide the input image and to specify other parameters followed by clicking at a couple of different locations along the membrane of cells to be identified. The program exports the membrane mask and/or the cell mask.

The program requires DipImage. The exported membrane and cell masks are DipImage-format images.

DownloadDijkstraNagy.p

The program automatically upgrades itself.

Find clusters in an image: clusterfind

Clusterfind is an application, requiring DipImage, which can be used to identify protein clusters in microscopic images. Clusters are identified by k-means clustering or edge detection (Sobel, Prewitt, Roberts, LoG, Canny). The segmented image can be fine-tuned: non-closed contours ("lines") can be removed, empty closed contours can be flood filled or manually-seeded watershed segmentation can be carried out to improve the result. You can even change the value of single pixels manually ("make-up"). The whole analysis procedure can be carried out on two images of the same size, and cluster statistics (including overlap %) are calculated.

Syntax: clusterfind

Help is available from the program.

Download: clusterfind.zip containing M-files and FIG-files

Analyze patch intensity distribution: analQDTI

The program analyzes the distribution of diffraction-limited fluorescent spots in a microscope image. The name derives from quantum dot triexciton imaging, an approach which significantly improves the resolution limit of confocal microscopes:

But the program can not only be applied to QDTI experiments...
Based on the distribution of fluorescent spots (i.e. their relative distances from each other) each spot is assigned to a large-scale cluster. Two spots are classified to belong to the same large-scale cluster if their distance is smaller than a user-defined distance. The centers of fluorescent spots are first identified by the program by searching for local minima. Then the user can modify these centers by manually deleting them or adding new ones. This step is followed by fitting of 2D Gaussians on every fluorescent spot. Initial values for the background and variance of the Gaussian are either estimated from the image by the program or given by the user. Fitting is performed either by a least-squares algorithm or maximum likelihood estimation. If peaks are closer to each other than a user-specified distance, the peaks are fitted simultaneously. The total fluorescence intensity in each spot is calculated from the fitted parameters (variance and height of the Gaussian) which can be used to estimate if the peak contains a monomer, dimer, trimer, etc. The program package can analyze homoclustering and heteroclustering as well. In the latter case two input images are required (fluorophore A and fluorophore B) and each identified peak is fitted in both images. In order to fit the observed total intensity distributions two monomer histograms are required corresponding to the (1:0) and (0:1) monomers, i.e. monomer of fluorophore A and monomer of fluorophore B) recoded in both fluorescence channels.

Syntax:

Help: available from within the program

Registration is required to run the main application (analQDTI). When running it for the first time, it will generate a code, which has to be emailed to me (peter.v.nagy@gmail.com) and I will send you a countercode.

Download the ZIP-file containing all the P-files of the application.

The application checks for updates after it is started.

Analyze RICS experiments: rics_tools

The program analyzes a RICS (raster image correlation spectroscopy) experiment which was described in Biophysical Journal in 2005 by the group of Enrico Gratton (Measuring fast dynamics in solutions and cells with a laser scanning microscope. Biophys J 89:1317-1327).The whole sequence of analysis can be performed by the program from reading the images to fitting the autocorrelation function.

Syntax: rics_tools

Help: available from within the program

Registrationis required to run the main application (rics_tools). When running it for the first time, it will generate a code, which has to be emailed to me (peter.v.nagy@gmail.com) and I will send you a countercode.

Download: ZIP file containing all the P-files of the application.

Orthogonal view of confocal stacks: confortho

The program generates an orthogonal view of a 3D confocal microscopic image stack. This functionality is similar to the one available in Zeiss LSM Image Browser, Leica LAS AF or Olympus FluoView. You might need confortho when you have to do image processing in MATLAB, and then you would like to view the processed images in the same way as you are used to. The program accepts images in MATLAB or DipImage (www.diplib.org) format.

Syntax: confortho

A brief help is available in the program.

Download: ZIP-file containing the program (P-file, FIG-file and help)

The program is also available in MATLAB Central.

Orthogonal view of confocal stacks: confortho2

This is an improved version of the program above.

  • By clicking on the "Import variable" button, it imports an image from the MATLAB workspace. It can import images with an arbitrary number of dimensions, and then the user will have to identify which dimension corresponds to the X, Y and Z spatial dimensions, and to time and different colors. Different color channels can be present in one of the dimensions of the imported image, or they can be in different cells of a cell array.
  • You have to identify which color a certain channel is to be displayed in, and the contrast stretching parameters. If "Global stretch" is activated, stretching is performed for the 3D dataset, if it is not selected, stretching is performed slice-by-slice.
  • Orthogonal viewing can be started by clicking on the "Show" button. In the orthogonal view, you can move the crosshair by clicking on the image, and you can change the viewed section by scrolling your mouse. 
  • You can move between different time points using the "Time slider".
  • You can copy the orthogonal view to the clipboard by clicking on the "Copy view" button.
  • The program automatically updates itself.
  • The program requires DipImage that can be downloaded at https://diplib.org/
  • Download the program here, and simply start it by typing "confortho2" at the MATLAB command prompt.