Measurements of Intensity Dynamics at the Periphery of the Nucleus

The aim of this chapter is to learn how to construct a workflow for measuring the fluorescence intensity localized to the nuclear envelope. For this purpose, the nucleus image is segmented to create a mask along the nuclear rim. The reader will learn a typical technique for automatically delineating the segmented area by post-processing using the mathematical morphology algorithm, and how to loop that piece of ImageJ macro and iterate through multiple image frames to measure changes in fluorescence intensity over time. This chapter is also a good guide for learning how to convert ImageJ macro commands recorded by the Command Recorder to a stand-alone ImageJ macro.


What You Learn from This Chapter
The aim of this chapter is to learn how to construct a workflow for measuring the fluorescence intensity localized to the nuclear envelope. For this purpose, the nucleus image is segmented to create a mask along the nuclear rim. The reader will learn a typical technique for automatically delineating the segmented area by post-processing using the mathematical morphology algorithm, and how to loop that piece of ImageJ macro and iterate through multiple image frames to measure changes in fluorescence intensity over time. This chapter is also a good guide for learning how to convert ImageJ macro commands recorded by the Command Recorder to a stand-alone ImageJ macro.

Introduction
In some biological research projects, we encounter problems that should be studied by measuring fluorescence intensity at the boundary between two different compartments. Here, we pick up an example analysis of the Lamin B receptor protein density targeting inner nuclear membrane. The protein changes its location from the cytoplasmic area (Endoplasmic Reticulum, ER) to the nuclear envelope (Boni et al. 2015).
We analyze a two-channel time-lapse image stack, a sequence of the process of the protein re-localization that causes increases in the protein density at the nuclear envelope. The data was acquired by Andreas Boni (Jan Ellenberg lab, EMBL Heidelberg) and have been used in many training workshops in EMBL as a great example for learning bioimage analysis. His work, with more advanced bioimage analysis workflows for analyzing the protein targeting dynamics, is published in The Journal of Cell Biology (Boni et al. 2015). Those codes and image data used in his study, which might be interesting for you after going through this chapter, are accessible through the supplementary data section in the journal website. 1 Two images shown in . Fig. 2.1 are from the first and the last time points of a timelapse sequence. 2 Compare these images carefully. The green signal broadly distributed in the cytoplasmic area at time point 1 becomes accumulated at the periphery of nuclei (red) at time point 15-between these image frames, the signal changed its localization from ER to the nuclear envelope. We construct a workflow that measures this accumulation process by writing an ImageJ macro. The workflow involves two steps: First, we segment the rim of nucleus-nuclear membrane-using the first channel (histone). Second, we use that segmented nuclear rim as a mask to measure the intensity changes over time in the second channel.
Segmentation of nucleus using its marker (e.g. DAPI) is a popular image analysis technique used in many biological research projects, but to measure more specific locationin our case nuclear envelope-we need to add several more steps to refine the region-of-interest. When we are successful in determining the area of nuclear envelope, the measurement of intensity in that region over time is rather trivial. We just need to loop the same process for each time point. Especially for the analysis of time-lapse sequence, programming is highly recommended to iterate the measurement for each time point. This chapter should be a good guide not only limited to study the intensity changes occurring at the nuclear envelope, but also in general for segmenting the edge (perimeter) of biological compartments such as the edge of organelle, plasma membrane and tissue boundaries. In principle, similar post-processing strategy is also applicable to 3D volumes by using 3D morphology filters.

Tools
We use Fiji (Fiji Is Just ImageJ) for image analysis. 5 Fiji 5 Download URL: 7 https://imagej. net/Fiji/Downloads 5 Please choose the latest version.
In addition, a plugin is required for loading the sample image data. Using the "Update sites" function, please add "CMCI-EMBL" to your Fiji installation. Please restart Fiji after this plugin installation.

Dataset
All ImageJ macro codes can be downloaded from the Github repository. 3 The image data we used in this chapter can be downloaded using the plugin "CMCI-EMBL". After installation of this plugin, select the menu item [EMBL > Sample Images > NPCsingleNucleus.tif] to load the image data. This is a time-lapse 3

Workflow
To simplify the development, we focus on a single cell/nucleus to construct the workflow. Load the image stack NPCsingleNucleus.tif. This is a hyperstack sequence. Slide the scroll bar at the bottom back-and-forth to watch the process of intensity changes. H2B-mCherry signal (red), used as a marker for nucleus, is more or less constant with its distribution. On the other hand, the Lamin receptor signal (green) exhibits strong accumulation to the nuclear membrane. To study this accumulation process, our aim is to measure the intensity changes of green signal intensity at the rim of the nucleus over time. The outline of the workflow is shown in the diagram (. Fig. 2.2).
To achieve this aim we first need to identify the region of nucleus rim ("segmentation")-in other words, we create a mask of the nucleus rim. Using this mask we measure the changes in intensity over time.

Segmentation of Nucleus Rim
We first write a macro for the nucleus rim segmentation by taking following steps: 1. Split the original multi-channel image stack and create two image stacks of each channel for processing them independently (. Fig. 2.3a) 2. Blur the image to attenuate noise (. Fig. 2.3b) 3. Nucleus segmentation: Binarize the image by intensity thresholding (. Fig. 2.3c) 4. Remove other Nuclei: At the right-bottom corner of the image, a small part of different nucleus is present. This should be removed. 5. Duplicate the image (a) Erode the original (. Fig. 2.3e) (b) Dilate the duplicated (. Fig. 2.3d) 6. Subtract the eroded from the dilated (. Fig. 2

.3f)
In the following we record these steps as macro commands using the Command Recorder ([Plugins > Macros > Record…]). We recommend you NOT to launch the command recorder from the beginning. Please first try to reproduce the workflow using mouse and the graphical user interface (GUI). This is like a rehearsal before recording your actions. When you become clear with the steps you have to take, record the processing steps. When you use the command recorder, be sure that "Macro" is selected in the "Record:" drop down menu at the top-left corner of the recorder. To split the multichannel image stack from the GUI menu, do [Image > Color > Split Channels]. In the Recorder you will see the following command. run("Split Channels"); run function is the most frequently used build-in macro function.  Executes an ImageJ menu command. The optional second argument contains values that are automatically entered into dialog boxes (must be GenericDialog or OpenDialog). Use the Command Recorder (Plugins>Macros>Record) to generate run() function calls. Use string concatenation to pass a variable as an argument. With ImageJ 1.43 and later, variables can be passed without using string concatenation by adding "&" to the variable name.
The run function takes a menu item as the first argument and optional values (values you fill-in in a dialog window) in the second argument. In case of channel splitting, there is no such optional value so the second argument is ignored. We then process the nucleus image. Click the nucleus image window to bring it up to the top-We call this action as "activating a window". By this clicking, we activated Channel 2 (red, nucleus image).
Please confirm that a new command shown below, is added to the recorder after activating the nucleus image. selectWindow("C1-NPCsingleNucleus.tif"); …Here is the explanation from the macro function reference.

selectWindow("name")
Activates the window with the title "name". This function takes a window title as an argument and activates a window with that title. When we used mouse to activate the nucleus channel window, we did it manually by visually recognizing the red nucleus image. On the other hand, in macro, we need to know the title of the windows of each individual channels to activate a specific window to provide it to macro as an argument of "selectWindow" command. How can we get the name of the nucleus channel window after splitting the channels of the original image?
Standard behavior of "Split Channel" command is that it automatically names the resulting stacks of individual channels by prefixing "C1-" or "C2-" or "C3" to the original image title. Based on this known behavior, we can construct these names if the original image title is known. For this we use the command getTitle( ) which returns the title of currently active window as a string.

Returns the title of the current image.
Here is the code to activate the nucleus channel automatically after the splitting. More importantly, we also acquire "image ID". This will be explained later.

Details:
5 The first line grabs the window title as a string variable "orgName". 5 The second line splits the stacks to each individual channel stack. 5 3rd and 4th lines compose the window title for each channel stack. 5 5th line activates the channel 1 stack. 5 6th line acquires the image ID of channel 1 stack. 5 7th line activates the channel 2 stack. 5 8th line acquires the image ID of channel 2 stack.
In lines 6 and 8, we acquire image IDs. Here is some more explanation about this: Each window has a unique ID number. To get this ID number from each image we use the command getImageID( ).

getImageID()
Returns the unique ID (a negative number) of the active image. Use the selectImage(id), isOpen(id) and isActive(id) functions to activate an image or to determine if it is open or active.
A window can be activated by selectWindow using its window title, but this could have a problem if there is another window with same name. Image ID has less problem since it is uniquely given to each window. To select a window using image ID, we use selectImage(ID) command.

selectImage(id)
Activates the image with the specified ID (a negative number). If id is greater than zero, activates the ID-th image listed in the Window menu. The ID can also be an image title (a string).
We acquire image IDs just after the splitting. From here on, we will use image IDs when we want to specify the image window we want to work on and to activate it.
? Exercise 2.1 Test the code below and run it on several image windows. Confirm that each window has an unique ID number. Please ignore the line numbers when you write the code.
Save the channel splitting macro. When you name the file, add an extension ".ijm", as this indicates that the file is an ImageJ macro. This is only a part of the final workflow, and we call such part as a "block" of the workflow, and by assembling blocks with various functions, we construct a workflow. A block is a functional unit within the workflow. Each block is consisting of several components, each of which is the build-in function that implements a certain algorithm (see 7 Chap. 1).
In the current case, we just finished the Channel Splitting Block, consisting of a channel splitter component, a window title getter component, an image window ID getter component, and window selector components.

Block 2: Segmentation of Nucleus Rim
Now we start working on the segmentation of nucleus rim. For this, we use only the nucleus image stack (channel 1) we got in the Block 1. Create a new tab in the script editor by [File > New]. We use this blank editor to write the next block for the detection of nucleus rim. We assemble all blocks as a single workflow later.
For this reason, we need to change the code so that it uses ImageID instead of a fixed image title. Since the ImageID of the nucleus channel was already acquired after splitting the original image, we can use that ID to activate a specific image window.
As we are working separately from the channel splitting block, we assume that the nucleus channel stack is active and is the top window at the starting of current code. We replace the first line selectWindow with getImageID( ) command to capture the ID number of the nucleus image window. Next, we need to add getImageID in line 10 and 13 to capture IDs of newly created windows. Due to these changes, we need to replace selectWindow in line 12 and 15 to selectImage to consistently use ImageID for accessing specific window. After these replacement, the updated code will look like the one shown below. code/code_block2_recordNucSegV2.ijm 1 orgID = getImageID(); 2 run("Gaussian Blur...", "sigma=1.50 stack"); 3 4 //run("Threshold..."); 5 setAutoThreshold("Otsu dark"); 6 setOption("BlackBackground", true); 7 run(Convert to Mask", "method=Otsu background=Dark calculate black"); 8 //run("Threshold..."); 9 run("Analyze Particles...", "size=800-Infinity pixel circular-ity=0.00-1.00 show=Masks display exclude clear include stack"); 10 dilateID = getImageID(); Here is the explanation of what was done. We are now almost done with the generalization of the nucleus rim segmentation block, but there still is a part that can be more general instead of a fixed window name. See line 12. This line uses run command to duplicate the "Mask" stack. run("Duplicate...", "title=[Mask of C1-NPCsingleNucleus-1. tif] duplicate range=1-15"); The first argument "Duplicate…" is the name of the menu item [Image > Duplicate…] and this is OK.
The second argument contains multiple optional values you chose in the GUI. The first is the title of the duplicated image, that was automatically created by suffixing "-1" to the image title. Square brackets surrounding this new image title is for avoiding the problem with spaces in the image title, because spaces are used as the separator for the options in the second argument. duplicate is a keyword of a checkbox in the duplication dialog, for choosing whether to duplicate multiple frames in a stack or just a single currently shown frame. The third option is the frame range (range=), which defines the range of frames to be duplicated. Since we want to duplicate all frames, the range is set to 1-15, from the first frame to the last 15th frame.
Within this second argument, two values in this command are not flexible enough for applying the macro to other images with different names. First is the image title. We better have a more general name for the duplicated image. The second is the frame range. The duplication of full stack is better be applicable for stacks with any number of frames, not limited to 15-frames stacks. We can construct the option string of the second argument as shown below to allow the general applicability of the macro. options = "title = dup.tif duplicate range=1-" + nSlices nSlices is a macro function that returns the number of frames or slices in the current stack. This macro function allows the duplication all frames of a stack, regardless of the number of frames within that stack.
We can now replace the second argument for image duplication by this new variable options.
run("Duplicate...", options); ? Exercise 2.2 Create a new script tab and write the code below (please ignore the line numbers when you write the code). Run the code with various stacks with different slice or frame numbers and confirm that this short macro successfully duplicate stacks with any slice or frame numbers.
1 print(nSlices); 2 options = "title=dup.tif duplicate range=1-" + nSlices; 3 print(options); 4 run("Duplicate...", options); Below is the upgraded code. All the lines previously commented out were removed, and line 10 was inserted for preparing options for the Duplicate command. In addition, we added line 19-24 for closing all images that are not needed anymore.

Block 3: Intensity Measurement Using Mask
Using the isolated nucleus rim image, we can specify the region for measuring the fluorescence intensity in the Lamin receptor channel. This will be the third block of the workflow.
Before start writing the third block of the workflow, we do a small preparation. We merge the rim-segmented stack and the Lamin receptor stack to create a multi-channel stack, which will be used as the input image data of this third block. Open the rim binary image (if you closed it already, run the second block macro again to regenerate it!) and the Lamin receptor image.
Two stacks can be merged to a two channel image stack by the following command.
[Image > Color > Merge Channels…] In the dialogue window, assign red color (C1) to the nucleus channel (nucleus rim binary image), and green color (C2) to the NPT channel. Make sure that "Create composite" is ticked. Clicking "OK" button, you will have an image stack that looks like . Fig. 2

.4.
We are now ready to start writing the third block of the workflow. Please follow the steps below using GUI. When you become sure with the operations, record your operations using Command Recorder.

[Image > Color > Split Channels…] 2. [Analysis > Set Measurements…]
5 You will see a dialog window with many check boxes (. Fig. 2.5). Among the parameters to be measured, tick at least Area, Mean gray value and Integrated density. Integrated density is the sum of all pixel values.

Activate the rim image and do [Edit > Selection > Create Selection]
5 This selects the background, not the rim.

[Edit > Selection > make Inverse]
5 Inverting the selection, now we are selecting the nucleus rim.
. You will then see results in the Results table such as shown in . Fig. 2.7. When you record these procedures by Command Recorder, the code will look like shown below. Create a new tab in the Script Editor and copy & paste (or it's possible to do the same by clicking "create" button in the Recorder).
In the 1st line, we split the multichannel stack to do processing individually. In the 3rd and the 6th lines, specific window titles are used. Just like we did in the first block, we need to convert these lines by composing window title of stacks for individual channel by adding prefixes. We also need to acquire their image IDs. For composing window titles, we just need to reuse the code we wrote already in the 7 Sect. "Block 1: Splitting Channels". code/code_block3_measurements.ijm 1 orgName = getTitle(); 2 run("Split Channels"); 3 c1name = "C1-" + orgName; 4 c2name = "C2-" + orgName; 5 selectWindow(c1name); 6 c1id = getImageID(); 7 selectWindow(c2name); 8 c2id = getImageID(); . Fig. 2.6 ROI selection of nucleus rim . Fig. 2.7 Results output 9 opt = "area mean centroid perimeter shape integrated limit display redirect=None decimal=3"; 10 run("Set Measurements...", opt); 11 selectImage(c1id); 12 run("Create Selection"); 13 run("Make Inverse"); 14 selectImage(c2id); 15 run("Restore Selection"); 16 run("Measure"); 5 Line 1: We first need to capture the title of the multi-channel image. 5 Line 2: Then the channels are separated into two stacks. 5 Line 3-4: Since we know the rule of how the resulting image stack names are, we construct titles each for channel 1 and channel 2. 5 Line 5-8: We then acquire image IDs. 5 Line 9-10: To be more explicit, we compose the measurement options as opt in line 9 and then use that variable opt as an argument for Set Measurements in line 10. 5 Line 11: Activate nucleus rim image using ImageID captured in line 6, instead of using selectWindow. 5 Line 12-13: Create nucleus rim ROI (a selection). 5 Line 14: Activate Lamin receptor image using ImageID captured in line 8. 5 Line 15: Restore the ROI created in line 13. 5 Line 16: We measure the region specified by the ROI created above.

? Exercise 2.3
Merge the nucleus rim and the Lamin receptor image stacks as described in the beginning of this section and test the code code_block3_measurements.ijm to measure the fluorescence intensity of the nuclear rim.

Integration: The Measurement Over Time
The code above measures only one time point. To measure the intensity changes over time, we need to add looping from line 11 to 16 in code_block3_measurements.ijm to repeat the measurement over time frames. For this, we need to modify the code by adding a for-loop. 9 opt = "area mean centroid perimeter shape integrated limit display redirect=None decimal=3"; 10 run("Set Measurements...", opt); 11 for (i =0; i < nSlices; i++){ 12 selectImage(c1id); 13 setSlice(i + 1); 14 run("Create Selection"); 15 run("Make Inverse"); 16 selectImage(c2id); 17 setSlice(i + 1); 18 run("Restore Selection"); 19 run("Measure"); 20 } In this updated code, following 4 lines were added for looping through the time lapse frames and measure successively. 5 A new line was inserted at line 11 to define the condition of for-looping. 5 A new line was inserted at line 13 to activate a specific frame in the nucleus rim stack. 5 A new line was inserted at line 17 to activate a specific frame in the stack. 5 A curly brace was added at line 20 to close the looping.

Integrating Segmentation and Measurements
Finally, we can assemble three blocks of code: the channel splitting block, the segmentation block and the intensity measurement block. As the third block, the intensity measurement block, starts with a two-channel stack (nucleus rim segmentation image and the Lamin receptor signal image), all we need to do is to insert the segmentation block between line 4 and line 5 of block 3 code code_block3_MeasurementOverTime.ijm. Instead of copy and pasting the segmentation block to the measurement block, a better way to do this is to convert the segmentation block to a user-defined function. Like all the macro commands that you see in the Build-in ImageJ macro function reference, we can create our own function by ourselves. We briefly learn how to write a custom function with a simple example.
If we have a code like below: Only several lines were added to the original code_block2_recordNucSegV3.ijm. 5 In line 1, we declare that this is a custom function named nucseg that takes a single argument orgID. In the original code, orgID, which is the imageID of the histone channel image, was captured using getImageID command. 5 Line 2 is commented out. This is because We do not need to do getImageID since the imageID of the histone channel image is provided through the argument of the function. 5 Line 3 is inserted, to explicitly activate the image with id orgId. 5 One line is inserted at line 21, to capture the imageID of the resulting image stackthe mask of nuclear rim-of Image Calculation in line 20. This imageID is named as a variable "resultID" in the function and is returned in the line 29 as the final output of the function. 5 run("Clear Results"); is added at the bottom (line 28) to clear the results table, as we want to have only the results of intensity measurement later. 5 In the last line, a curly brace is added to mark the boundary of function.

Results and Conclusion
The final output is a list of nucleus rim intensity values for each time point in Results window. These values can be saved in a CSV file and further analyzed using other software tools more suited for data analysis such as R or Python. Here, to summarize the analysis in this chapter, we plot the changes in the total fluorescence intensity over time using ImageJ Macro code_plotResults.ijm (. Fig. 2.8). The code appears after the paragraph below.
The plot in . Fig. 2.8 shows an increase in total fluorescence intensity by 1.3-folds in the initial five time points, and then it becomes mostly constant. To know the baseline level intensity more precisely, it might be better to start the imaging and measurement from an earlier time point. In addition, ideally, more measurements could be done with other nuclei to compute an averaged curve for a more reliable results.
5 Line 2 creates a new array for storing intensity measurements listed in the Results table. nResults is a build-in function that returns number of rows in the table. This array will be the Y-axis value in the plot. 5 Line 3-4 gets the result of non-calibrated integrated density (Column "RawIntDen") of each row, and divide that value by the integrated density at the time point 0 (the first frame). International License (7 http://creativecommons. org/licenses/by/4. 0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made. The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.