Skip to content

Commit 52fe08e

Browse files
committed
docs: reformat text and fix inaccuracies
1 parent dd4d43c commit 52fe08e

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

docs/Tutorials/Find ROI average in Stack.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,112 @@ The point of this tutorial is to show how to decode a stack of images and how to
22

33
## Synopsis
44

5-
This tutorial demonstrates how to use ImageJS to decode a TIFF stack of images and analyze frame-by-frame changes, particularly focusing on regions of interest (ROIs) in pulsar images. The process involves:
6-
Using the fs library we read and decode the TIFF stack.
7-
Then,utilizing the `maxImage()` function to get the image with the maximum pixel values across the stack.
8-
We identify regions of interest from the maximum value image using a threshold mask and obtaining their coordinates.
9-
Finally we compute the average pixel value for each ROI across all images in the stack, storing the results in a map.
10-
We can use this data to analyze changes in intensity over time.
5+
This tutorial demonstrates how to use ImageJS to decode a TIFF stack of images and analyze frame-by-frame changes, particularly focusing on regions of interest (ROIs) in pulsar images.
6+
7+
- Using the `fs` library we read and decode the TIFF stack.
8+
- Then,utilizing the `maxImage()` function, we get the image with the maximum pixel values across the stack. Since we need to use `threshold()`to find ROI, we must check if its `colorModel` is `"GREY"`. If not, image must be grayscaled.
9+
- We identify regions of interest from the maximum value image using a threshold algorithm and obtain their coordinates.
10+
- Finally we compute the average pixel value for each ROI across all images in the stack, storing the results in a map.
11+
We can use this data to analyze changes in intensity over time or compare changes in its position.
1112

1213
```ts
1314
const buffer = fs.readFileSync('/path/to/file.tiff');
1415
const stack = decodeStack(stack);
15-
const maxValueImage = stack.maxImage();
16+
17+
let maxValueImage = stack.maxImage();
18+
//We will use `threshold()` to find ROIs
19+
//therefore color model has to be "GREY".
20+
if (maxValueImage.colorModel !== 'GREY') {
21+
maxValueImage = maxValueImage.grey();
22+
}
1623
const maxValueMask = maxValueImage.threshold();
1724
const roiMap = fromMask(maxValueMask);
1825
//Provides all the regions of interest.
1926
const rois = roiMap.getRois();
20-
const stackGrays = new Map<number, number[]>();
27+
const stackGrays = new Map<number, number[][]>();
2128
for (const roi of rois) {
2229
const stackAvgs = [];
2330
const roiPoints = roi.absolutePoints;
2431
for (const image of stack) {
2532
const avgValue = image.mean({ points: roiPoints });
26-
//Gets value from one channel since it is grayscaled.
27-
stackAvgs.push(avgValue[0]);
33+
stackAvgs.push(avgValue);
2834
}
2935
stackGrays.set(roi.id, stackAvgs);
3036
}
3137
```
3238

39+
Here is a more detailed review of these steps.
40+
3341
## Decode the Stack
3442

35-
ImageJS has the ability to decode a `tiff` stack of images. Images in stack can represent frame-by-frame successive changes. This way we can take a look dynamically at changes that happen to regions of interest.
43+
ImageJS has the ability to decode a TIFF stack of images. Images in stack can represent frame-by-frame successive changes. This way we can take a look at dynamic changes that happen to regions of interest.
3644
In our specific case here, we have a stack of pulsar kind of images. We can use ImageJS to figure out when the region is shown in the image and when it isn't by looking at the average value of said region.
3745

38-
Just like any image, after getting our stack needs to be parsed fo us to work with data. ImageJS doesn't have a built-in function to parse tiff stack, so you will have to use
39-
`fs` library.
46+
Just like any image, after getting our stack needs to be parsed fo us to work with data.
4047

4148
```ts
49+
//ImageJS doesn't have a built-in function to parse TIFF stack,
50+
//so use `fs` library.
4251
const buffer = fs.readFileSync('/path/to/file.tiff');
4352
const stack = decodeStack(stack);
4453
```
4554

4655
## Find the image with maximum values:
4756

48-
Stack class has a function called `maxImage()`. It will give us the maximum value of each pixel throughout the stack. We will use this image as a reference for all other images, to locate all possible regions of interest.
57+
Stack class has a function called `maxImage()`. It will give us the maximum value of each pixel throughout the stack. We will use this image as a reference for all other images to locate their ROIs.
4958

5059
```ts
5160
const maxValueImage = stack.maxImage();
61+
//We will use `threshold()` to find ROIs
62+
//therefore color model has to be "GREY".
63+
if (maxValueImage.colorModel !== 'GREY') {
64+
maxValueImage = maxValueImage.grey();
65+
}
5266
```
5367

5468
![Image](./images/stackAvg/maxImage.png);
5569

5670
## Locate ROIs
5771

58-
From our "maxValues" image we can find all the regions of interest. To be precise we need their coordinates to apply them to other images.
72+
From our `maxValueImage` image we can find all the regions of interest. To be precise we need their coordinates to apply them to other images.
5973

6074
```ts
6175
const maxValueMask = maxValueImage.threshold();
6276
const roiMap = fromMask(maxValueMask);
77+
```
78+
79+
![Mask](./images/stackAvg/maxMask.png)
80+
81+
```ts
6382
//Provides all the regions of interest.
6483
const rois = roiMap.getRois();
6584
```
6685

67-
![Mask](./images/stackAvg/maxMask.png);
86+
![Painted ROIs](./images/stackAvg/paintedROIs.png)
6887

6988
## Find average value of each ROI on each image
7089

71-
After we found all the ROIs on the "maxValue" image, we take each region and check its average value on every image in the stack.
90+
After we found all the ROIs on the `maxValueImage`, we take each region and check its average intensity on every image in the stack.
7291
It will look something like this:
7392

7493
```ts
75-
const stackGrays = new Map<number, number[]>();
94+
const stackGrays = new Map<number, number[][]>();
7695
for (const roi of rois) {
7796
const stackAvgs = [];
7897
const roiPoints = roi.absolutePoints;
7998
for (const image of stack) {
8099
const avgValue = image.mean({ points: roiPoints });
81100
//Gets value from one channel since it is grayscaled.
82-
stackAvgs.push(avgValue[0]);
101+
stackAvgs.push(avgValue);
83102
}
84103
stackGrays.set(roi.id, stackAvgs);
85104
}
86105
```
87106

88-
This will create a map where the key is the ID of each ROI, and the values are an array of average values of ROI coordinates across all the images in the stack.
107+
This will create a map where keys are IDs of each ROI, and values are an array of pixels with average intensity across all the images in the stack.
89108
This way we can take a look at the changes in intensity of ROI from one image to another.
90109
This will give us the graph of intensities across all the images in the stack for each ROI.
110+
For instance here we have a graph of intensity of region with ID of 9. We can see that there is a rising pulse between images 1 and 4, but then it disappears.
91111

92-
### Add graph image
112+
![ROI 9](./images/stackAvg/ROI9.png)
113+
![ROI 9 graph](./images/stackAvg/graphROI9.svg)

0 commit comments

Comments
 (0)