# Hematoxylin & Eosin Staining Image

## Why Hematoxylin & Eosin Staining Image?

Hematoxylin and eosin stain (H\&E stain) is a widely used tissue stain that provides histologic information for medical diagnosis and is considered the gold standard. Hematoxylin mainly stains cell nuclei in purplish blue, and eosin colors cytoplasm and extracellular matrix in different shades of pink. By integrating spatially resolved sequencing-based feature data generated from Stereo-seq with the H\&E staining image, the morphology of cells can be linked with spatially localized feature expression. The combined use of histology images and feature expression co-representation increases the amount of information that a tissue slice can provide.

## Considerations for H\&E Staining Images

Stereo-seq chip is a non-transparent silicon chip, so the H\&E stained image should be scanned by a bright-field microscope using reflective light. The background color of the H\&E image is close to white, and the representation of tracklines is lighter white. Different from fluorescence images, which only illustrate relatively simple information with shades of gray, H\&E staining images provide sophisticated histopathology information by combining R-G-B colors. Therefore, the file size of an RGB image is much larger than a grayscale image in the same dimensions, and the required computing resources are much higher. Currently, StereoMap requires a minimum of 16GB RAM, which is only sufficient for processing a 24-bit color, 10X objective image for a 1 cm x 1 cm chip.

Processing H\&E images in StereoMap and SAW requires an individual acquisition stored in a single-page color file at 24-bit depth. (See [Image Types and Format](https://stereotoolss-organization.gitbook.io/stereomap-user-manual/tutorials/navigation-for-image-processing/..#image-types-and-format) for more information)

<table><thead><tr><th width="201">Bright-field Image</th><th>Data Type and File Format</th></tr></thead><tbody><tr><td>Color image</td><td>One 24-bit color single-page image file</td></tr></tbody></table>

## Step 1: Upload Image

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F9Xc9tDTSXvorickA4blR%2Fcolor-select%20image%20file.png?alt=media&#x26;token=cf72e27a-ee65-4279-9401-dfb7d9ad0d7e" alt=""><figcaption></figcaption></figure>

Click on **Choose file** in the drag-and-drop box to select a compatible image file from your file system. You can also drag your selected file and drop it in the box. Only one image file is allowed for this image type.

Please visit [Image Processing Input Files](https://stereotoolss-organization.gitbook.io/stereomap-user-manual/getting-started#image-processing-input-files) for detailed image file information.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Fh66Ftqrn1zrL0GlynUqy%2Fcolor-image%20parsing%20info.png?alt=media&#x26;token=3a2e4f9b-3a0a-4c4c-a8f4-7333855bb37c" alt=""><figcaption></figcaption></figure>

Selecting a file triggers a file-parsing process that not only reads the image but also acquires necessary data from the input. Depending on the file type and image size, the parsing time can vary. Stereo-seq chip serial number (SN) and microscope setting provide important information in the image processing steps. The `.tar.gz` or `.stereo` the input file contains these data. However, if the input file format is `.tif` or `.tiff`, you need to enter the required information specified in this step to begin the image parsing and quality check. Specifically, you’ll be asked to input details about the microscope by choosing a microscope configuration. Refer to the [Microscope Settings](https://stereotoolss-organization.gitbook.io/stereomap-user-manual/download#microscope-settings) for additional details.

## Step 2: Image Registration

In this step, you will need to adjust the orientation, position, and scale of the image to align it with the spatial feature expression matrix.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Fa5QKUt7arukg2OSTljQV%2Fcolor-regiatration.png?alt=media&#x26;token=6c8682d1-cf64-4536-aba2-4d1fb0866cfb" alt=""><figcaption></figcaption></figure>

If you upload the `.stereo` file in step 1, you can see the image and the spatial feature expression matrix once enter step 2. For `.tar.gz` or `.tif/.tiff` image file, you will need to add a `.stereo` file for specifying a spatial feature expression matrix as the reference. Click <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FOfxGMNPzUX5WM2xEzQ4U%2Fadd_new.png?alt=media&#x26;token=e10c64d5-a4ed-4e38-9c75-942708fb5c11" alt="" data-size="line"> to select the `.stereo` file. Also, if your image is in the `.stereo` file, but you need to change the reference expression matrix, you can click the <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Ffs9w6EjRE0moYxmxgyuL%2Freplace.png?alt=media&#x26;token=f2a4d3b1-1b8d-48ac-aae9-0304a8be8ff8" alt="" data-size="line"> and load a new file. This action will reload the matrix, but use the image from step 1.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FxkndkDb0cQTOyL3WPjTa%2Fcolor-add%20or%20replace%20matrix.png?alt=media&#x26;token=fbfb82fa-9e29-4380-a5be-4bb0abf4e58b" alt=""><figcaption></figcaption></figure>

The registration process involves two stages, roughly matching the orientation of the image based on the morphology and finely adjusting the position and scale for exact overlap with the the spatial feature expression map. You can also choose "Chip tracklines" to display tracklines that are derived from the spatial feature expression matrix to help with fine alignment.

To roughly align the image, you need to match the microscope image and the feature density map in orientation.

* Use the **Flip tool** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FnH73LJ6vjmoU302587pN%2FFlip.png?alt=media&#x26;token=764dda23-d68a-4a3a-9cb2-b1bf6cd76e62" alt="" data-size="line"> to mirror the image.
* Click on <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FNiFoaF6sNu3HtwAY01oF%2FRotation.png?alt=media&#x26;token=0edc49a6-3bbc-481f-a4e9-ffb3cb36f1c9" alt="" data-size="line"> and use the **Control knob** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FSy1X3yWeTQHJEOxJ37Xs%2Fcontrol_knob.png?alt=media&#x26;token=ca51c1b4-f5b4-45fe-b9aa-5859153bf652" alt="" data-size="line"> to rotate the image in the same direction.

Once the orientation of the image and the spatial feature expression matrix have matched, you can move on to the fine-alignment steps.

In the fine-alignment stage, you will need to move the image to the place where the tissue can overlap.

* Use the **Move panel** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FyhCkukujAHlLjmSl9PAQ%2FStep%20move.png?alt=media&#x26;token=de588721-c577-495d-bd58-455028891b1e" alt="" data-size="line"> by setting the step size and pan move in four directions.
* The dimension of the microscope image might differ from the spatial feature expression map, you can adjust scales using the **Scale tool**<img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F3T9DdUcaKvhrdWgxCRs3%2Fscale.png?alt=media&#x26;token=0c406ad2-501e-498a-8f21-49f3b79d8e6f" alt="" data-size="line">.

You can align the image by checking "Chip tracklines" to show the reference trackline template and let the tracklines fall directly overlapped. At this time, the chip trackline template is a representation of the matrix. If the tracklines are dim, the **Normalization** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F4VBocEilXEK2uuRIVuZd%2Fnormalization.png?alt=media&#x26;token=49da7adf-8ab4-4105-93a4-e235ec3d1c15" alt="" data-size="line"> , **Contrast** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FDVpKxUpwNcQDLF6Dcvta%2FContrast.png?alt=media&#x26;token=c0b45016-95e0-4e88-ab6d-ccec99d38508" alt="" data-size="line">, **Brightness** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FWS5FBdWiYXua99J9z5pG%2Fbrightness.png?alt=media&#x26;token=868b2e24-57ae-45ea-ad65-c348819046aa" alt="" data-size="line">, **Opacity** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FNLUcFVGSQaBj3jT5mRhV%2Fopacity.png?alt=media&#x26;token=654f0893-7294-45c9-bcea-d22a4292aec8" alt="" data-size="line">, and **Saturation** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FwTCPv8qijlzGWobcLkAR%2Fsaturation.png?alt=media&#x26;token=1d8181b1-329a-4015-9ec9-75b269b8b2bd" alt="" data-size="line"> of the image can be adjusted manually.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Fnk87faL6QO4wI3jXP5h7%2Fcolor-chip%20tracklines.png?alt=media&#x26;token=7c1356db-8948-44eb-8d8d-23c8784b1323" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The images are adjusted to optimize the visibility of tracklines.
{% endhint %}

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FgNkVXEmSFwTTHTyjauyS%2Fcolor-trackline%20overlap%20example.png?alt=media&#x26;token=c64e97d2-8bda-483d-a07d-0f15b2f10a63" alt=""><figcaption><p>Example of trackline overlapping</p></figcaption></figure>

The image that has been adjusted will be marked as complete by <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FiKOvBmKjicddI0Mk0xYJ%2Fchecked.png?alt=media&#x26;token=b3561dfb-3061-4497-9dae-5fc0ca8313a0" alt="" data-size="original">.

{% hint style="info" %}
After the image has been aligned with the matrix, steps 3 and 4 can be bypassed. You can export the semi-processed `.tar.gz` image directly and feed this output to SAW for automatic segmentation.

In addition, a `*regist.tif` image file will be provided. This is a reoriented image that matches the shape and orientation of its corresponding feature expression matrix. This image serves as the starting point for tissue and cell segmentation. **If you’re considering using other external segmentation tools or algorithms, it’s strongly advised to utilize this `*regist.tif` file as the input.**
{% endhint %}

## Step 3: Tissue Segmentation

{% hint style="info" %}
**Tissue Segmentation** is a skippable step.
{% endhint %}

In this step, you will identify the tissue regions. Accurately identifying the boundaries of the tissue can significantly reduce the interference from the background in the clustering result. The image-based tissue segmentation result will be mapped onto the sequencing-based spatial feature expression matrix to create a feature density map of the tissue region.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FlbeqT6fqLvwqlHiFE27z%2Fcolor-tissue%20seg.png?alt=media&#x26;token=a85ebdba-0623-4f88-b4fd-27789d6eec19" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you upload the `.stereo` file in step 1, you can see a semi-transparent mask overlapped on the registered microscope image.

For `.tar.gz` or `.tif/.tiff` image file, you will need to use tools to draw the tissue region.
{% endhint %}

In the Tissue Segmentation step, you have the option to edit the mask that was previously recorded or create a new one. Tissue mask that was recorded in the `.tar.gz` or `.stereo` file will be labeled as "**RECORD**" in the Segmentation mask dropdown menu, while the mask created by drawing or importing will be labeled as "**CUSTOM**". To change the active mask displayed in the canvas, simply select from the **Segmentation mask** dropdown.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FLHTTm7IYGCTGVBrZCiAw%2Fcolor-tissue%20mask%20tag.png?alt=media&#x26;token=608670ad-859b-4450-bd4a-40b3a7bf578c" alt=""><figcaption></figcaption></figure>

To select or edit the tissue region, use a combination of **Lasso** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Fcv7ecDyabawGId1NsF4a%2Flasso.png?alt=media&#x26;token=49e25c42-659c-4dac-b404-c1166110c3ec" alt="" data-size="line">, **Brush** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F1D3sxxiMC1mJNNN2nTQM%2Fpencil.png?alt=media&#x26;token=11c31d65-7901-45ef-ae27-f8b56c9f383b" alt="" data-size="line"> , and **Eraser** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FJWblMsAJp5emMnp1Dh8S%2Feraser.png?alt=media&#x26;token=483f6396-7cb4-4102-b38d-8db50e1c01da" alt="" data-size="line"> tools. **Lasso** is typically used for selecting or deselecting large areas, while the **Brush** and **Eraser** tools are more suitable for smaller areas, such as regions around tissue or small holes in the tissue.

<div><figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FSylNUzTKSR0NrcKoHrUZ%2Fcolor-tissue%20mask%20lasso.png?alt=media&#x26;token=9d286248-b645-4fb3-b276-7686296ed903" alt=""><figcaption><p>Lasso</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FrCOWzqLvK9KYrG4mJEXS%2Fcolor-tissue%20mask%20brush.png?alt=media&#x26;token=b0b95c4f-f027-49a0-ba81-b30d440f33dc" alt=""><figcaption><p>Brush</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FZsh0lOvOpXGJB91Zb5P3%2Fcolor-tissue%20mask%20eraser.png?alt=media&#x26;token=4a62cb42-c534-402f-9c9a-7b973be734f0" alt=""><figcaption><p>Eraser</p></figcaption></figure></div>

If you have created a `.tif` format binary mask file using a third-party tool, you can import it by clicking on the **Segmentation mask** dropdown on the right panel and then clicking <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FOfxGMNPzUX5WM2xEzQ4U%2Fadd_new.png?alt=media&#x26;token=e10c64d5-a4ed-4e38-9c75-942708fb5c11" alt="" data-size="line">. If the imported result is unsatisfactory, you can replace it by clicking <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Ffs9w6EjRE0moYxmxgyuL%2Freplace.png?alt=media&#x26;token=f2a4d3b1-1b8d-48ac-aae9-0304a8be8ff8" alt="" data-size="line"> to import a new mask.

<div><figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FKi49aLtI85rfjei3RID2%2Fcolor-tissue%20mask%20import.png?alt=media&#x26;token=1b72efc5-430b-41ee-980b-d6fa62c90a21" alt=""><figcaption><p>Import tissue mask</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FNyaQMtVOzGr3F1ELnpE5%2Fcolor-tissue%20mask%20import%20result.png?alt=media&#x26;token=c884f466-3de9-4fa7-9a8e-3a0e17a30581" alt=""><figcaption><p>Show the file name of the imported mask</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F3xCmtaMCwaep77QbRrYo%2Fcolor-tissue%20mask%20replace.png?alt=media&#x26;token=7f942ae9-48a8-4b81-bf58-b7e36b6b817d" alt=""><figcaption><p>Replace the mask</p></figcaption></figure></div>

## Step 4: Cell Segmentation

{% hint style="info" %}
**Cell Segmentation** is a skippable step.
{% endhint %}

Cell identification and segmentation are the fundamental steps in generating spatially resolved single-cell feature expression data. For H\&E images, segmentation can be performed on either nucleus regions or cell regions.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FavhiVTAqTJxhxxoplTGl%2Fcolor-cell%20seg.png?alt=media&#x26;token=72c4782b-72bb-4855-92fd-a9f74bc4a1a6" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you upload the `.stereo` file in step 1, you can see the red outlines of the cells/nuclei on the registered microscope image.

For `.tar.gz` or `.tif/.tiff` image file, you will need to use tools to label cells.

Cell segmentation is applicable only within the tissue region. Therefore, the areas not encompassed in the Step 3 Tissue Segmentation will appear as a white background.

![](https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FNY1IemKeTWQUKhnhRG6S%2Fcolor-cell%20seg%20zoom.png?alt=media\&token=ed9a9ac4-8318-4def-9bf4-5b9bd5ead9ce)
{% endhint %}

Similar to Tissue Segmentation, you have the option to edit the mask that was previously recorded (tagged with "**RECORD**") or create a new one (tagged with "**CUSTOM**"). Change the active mask by selecting from the **Segmentation mask** dropdown.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FisrTqDPiqfgn5Hgd5S8E%2Fcolor-cell%20mask%20tag.png?alt=media&#x26;token=d3555992-f63c-437c-8aa9-134043999d50" alt=""><figcaption></figcaption></figure>

Use the **Lasso** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Fcv7ecDyabawGId1NsF4a%2Flasso.png?alt=media&#x26;token=49e25c42-659c-4dac-b404-c1166110c3ec" alt="" data-size="line">, **Brush** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F1D3sxxiMC1mJNNN2nTQM%2Fpencil.png?alt=media&#x26;token=11c31d65-7901-45ef-ae27-f8b56c9f383b" alt="" data-size="line"> , and **Eraser** <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FJWblMsAJp5emMnp1Dh8S%2Feraser.png?alt=media&#x26;token=483f6396-7cb4-4102-b38d-8db50e1c01da" alt="" data-size="line"> tools to select or edit cells. **Lasso** is best for use in deselecting large areas such as background, while the **Brush** and **Eraser** tools are more suitable for smaller areas, such as marking cells or separating cell clusters.

<div><figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F2NrncCZeNFijX72lNTqe%2Fcolor-cell%20mask%20lasso.png?alt=media&#x26;token=6074675a-30b7-43e4-92a5-ce93b9c8c6df" alt=""><figcaption><p>Lasso to select a cell</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FVutFhVe5iDg5q7H1rkFO%2Fcolor-cell%20mask%20lasso%20deselect.png?alt=media&#x26;token=71e013d4-7542-4a8f-b710-10a9bfc5bcb6" alt=""><figcaption><p>Lasso to deselect some cells</p></figcaption></figure></div>

<div><figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FQV7VRsaX7fZsKox4zhfK%2Fcolor-cell%20mask%20brush.png?alt=media&#x26;token=04bc5174-0e82-4b3f-9dce-76db29b4c9b4" alt=""><figcaption><p>Brush</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FLzBuufAR5x3jJPXz5on2%2Fcolor-cell%20mask%20eraser.png?alt=media&#x26;token=f5b7a9bf-4bdd-432b-8edb-b9f1d64ca922" alt=""><figcaption><p>Eraser</p></figcaption></figure></div>

It is recommended to import a`.tif` format cell mask file created from the registered image by any third-party tools. You can import it by clicking on the **Segmentation mask** dropdown and then accessing your file system by clicking <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FOfxGMNPzUX5WM2xEzQ4U%2Fadd_new.png?alt=media&#x26;token=e10c64d5-a4ed-4e38-9c75-942708fb5c11" alt="" data-size="line">. If the imported result is unsatisfactory, you can replace it by clicking <img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Ffs9w6EjRE0moYxmxgyuL%2Freplace.png?alt=media&#x26;token=f2a4d3b1-1b8d-48ac-aae9-0304a8be8ff8" alt="" data-size="line"> to import a new mask.

<div><figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FRfhE0Jrlct854OC3rSnz%2Fcolor-cell%20mask%20import.png?alt=media&#x26;token=a275b677-00e9-4798-a1fe-1226261b22e2" alt=""><figcaption><p>Import cell mask</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FYGC8siKRT0kCViSOR5Su%2Fcolor-cell%20mask%20import%20result.png?alt=media&#x26;token=928a4f95-58ad-4f37-bc91-5684ceb46f4c" alt=""><figcaption><p>Show the file name of the imported mask</p></figcaption></figure> <figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2Fzb4N6RH9WFXrthSsgr4V%2Fcolor-cell%20mask%20replace.png?alt=media&#x26;token=ca02d1db-9368-4be6-912b-10405eed2894" alt=""><figcaption><p>Replace the mask</p></figcaption></figure></div>

## Step 5: Export

The final step is to export the results of image registration, tissue segmentation, and cell segmentation. Click **Export image processing record** to generate a `.tar.gz` file.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2FEzJ6dWO4Xzp1hNjZrgvr%2Fcolor-export.png?alt=media&#x26;token=f28669a1-b7f2-4a0b-a69c-8b307aaba3e8" alt=""><figcaption></figcaption></figure>

This output file can be located in your file system, specifically under the **StereoMapWorkspace** -> **Processing** folder, which is in your designated saving path. The [saving path](https://stereotoolss-organization.gitbook.io/stereomap-user-manual/download#saving-path) can be modified in [Setting](https://stereotoolss-organization.gitbook.io/stereomap-user-manual/download#setting). If you have manually adjusted the image alignment with the matrix, you will also find a `*regist.tif` file in your output folder. Alternatively, this TIFF file can be located in the SAW output directory under the `/outs/` folder.

<figure><img src="https://917529218-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPjxR1Lv74t5QCTxNb8d%2Fuploads%2F5bvWyMwepBsqdnZt9uth%2Fcolor-export%20directory.png?alt=media&#x26;token=a10655bb-7791-4dbc-9b52-de4a5a6c41b6" alt=""><figcaption></figcaption></figure>

The `.tar.gz` file contains the original image and records of the manual process. This file will be used in SAW to analyze sequencing data and images together. The internal structure of the `.tar.gz` is fixed and modification of the structure or any of the files in it is not recommended.

The `*regist.tif` file is a registered image that has been cropped and resized to match the dimension of the feature expression matrix. It can be utilized in any third-party tool, and the resulting data can be re-imported to StereoMap.

## Pass the TAR.GZ to SAW Pipeline

There are two options for transferring the output of Image Processing to SAW.

One option is to use the `--image-tar` argument to feed the `.tar.gz` file into the `SAW count` pipeline. This will process the image together with the Stereo-seq FASTQ files and produce the HTML summary report.

```bash
cd /saw/runs

saw count \
    --id=<ID> \
    --sn=<SN> \
    --omics=<OMICS> \
    --kit-version=<TEXT> \
    --sequencing-type=<TEXT> \
    --chip-mask=/path/to/chip/mask \
    --organism=<organism> \
    --tissue=<tissue> \
    --fastqs=/path/to/fastq/folders \
    --reference=/path/to/reference/folder \
    --image-tar=/path/to/image/tar
```

Another choice is to use the `--realigned-image-tar` argument to input the `.tar.gz` file into the `SAW realign` pipeline. `SAW realign` will bypass the CID mapping and genome alignment steps, and re-generate aligned images, obtain the feature expression matrix at tissue and cell level, and produce an updated HTML report.

```bash
cd /saw/runs

saw realign \
    --id=<ID> \
    --sn=<SN> \
    --count-data=/path/to/previous/SAW/count/task/folder/id \
    --realigned-image-tar=/path/to/realigned/image/tar
```
