Welcome to the web
page of  Peter Nagy

Click here to edit subtitle

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 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 my PhD students. Below I give you a selection of the utilities I developed.


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 from within the program.

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

The program is also available on MATLAB Central.


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_type_1: membranes are highlighted

output_type_2: cells are labeled

Output arguments are optional.

Input arguments:

image: the input image to be segmented

output_type: 1 - membranes are highlighted, 2 - cells are labeled, 3 - both

connectivity: 4 - 4-connected, 8 - 8-connected

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

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.

Download: DijkstraNagy.p

The program automatically checks for upgrades and upgrades itself.


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 ZIP-file containing P-files and FIG-files.


It is a utility containing three functions (granulometry, top-hat transform, k-means clustering) often used in analysis of protein clusters. These operations are unrelated, the common denominator is that I often use them.

Syntax: clustering_toolbox

Brief help is available by typing "help clustering_toolbox" at the Matlab command prompt.

Download ZIP-file containing P-file and FIG-file.


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 (Subdiffraction fluorescence imaging of biomolecular structure and distributions with quantum dots, Heidbreder et al., BBA, 1803: 1224-1229Quantum dot triexciton imaging with three-dimensional subdiffraction resolution, Hennig et al., Nano Lett., 9: 2466-70.) 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.


  • analQDTI - start the main application
  • checkAllPeaks(imageIn,peakParameters,widthToPlotInFWHM) - to visually inspect the 3D overlay (surface plot) of the original data and the fit
  • totIntMonHist - generate the monomer histograms required by totIntFitConvolution to estimate the fraction of different n-mers.
  • totIntFitConvolution - fit the observed intensity distribution with monomer, dimer, trimer (or heteromers in the case of analysis of heteroclustering) to estimate the fraction of different n-mers.

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 ([email protected]) and I will send you a countercode.

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


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 readin the images to fitting the autocorrelation function.

Syntax: rics_tools

Help: available from within the program.

Registration is 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 ([email protected]) and I will send you a countercode.

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


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:

  • mean, trimmed mean (trimming % can be given), median, SD, SEM, number of pixels, lowest and highest pixel value
  • intensity histogram whose bin specifications can be given.

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

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

Syntax: mask_evaluate

Download the file below:


The application checks for updates after it is started.


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:

  • mask output: pixels corresponding to the ROI are "1", the rest of the pixels are "0"
  • color output: the ROI is overlaid on the original image in red.

This is how to draw the ROI:

  • click on every corner of the polygon ROI
  • if you want to finish drawing the ROI, ALT-click or double-click
  • Exit: double-click after finishing a ROI, finish ROI with SHIFT-click
  • Draw rectangle ROI - ALT-click and drag
  • Draw square ROI - SHIFT-click and drag

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)
imageToDrawOn - the image you would like to draw to ROI on
linecol - color of line to draw with followed by a string specifying the color according to the short (e.g. 'b') or long (e.g. 'blue') specification of Matlab
closeline - 0=don't close the line; 1=close the line
timesdilate - number of times the line is to be dilated (only interpreted if the ROI type is "line")
roitype - 1=filled object; 2=line
radius - radius of circles drawn at the vertices of polygons
  • Optional output arguments: 1st output argument - mask image; 2nd output argument - color output image

Download the file below:


The application checks for updates after it is started.

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 under Matlab. Therefore, BioFormats must be installed. Since DipImage is the default output image type, DipImage must also be installed.
  •  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.

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.