Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit e3ce124

Browse files
committed
refactor: replace enums with const objects
Closes: #140
1 parent 7a7933b commit e3ce124

File tree

126 files changed

+654
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+654
-743
lines changed

demo/components/CameraTransform.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RefObject, useEffect, useRef, useState } from 'react';
22

3-
import { Image, ImageColorModel, readCanvas, writeCanvas } from '../../src';
3+
import { Image, readCanvas, writeCanvas } from '../../src';
44
import { convertColor } from '../../src/operations/convertColor';
55
import { useCameraContext } from '../contexts/cameraContext';
66

@@ -56,8 +56,8 @@ export default function CameraTransform(props: CameraTransformProps) {
5656
image,
5757
snapshotImageRef.current,
5858
);
59-
if (result.colorModel !== ImageColorModel.RGBA) {
60-
result = convertColor(result, ImageColorModel.RGBA);
59+
if (result.colorModel !== 'RGBA') {
60+
result = convertColor(result, 'RGBA');
6161
}
6262
writeCanvas(result, canvasOutput);
6363
} catch (err) {

demo/components/comparisonFunctions/testComputeSsim.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Image, ImageColorModel } from '../../../src';
1+
import { Image } from '../../../src';
22
import { computeSsim } from '../../../src/compare/computeSsim';
33

44
/**
@@ -21,7 +21,7 @@ export function testComputeSsim(image: Image, snapshot: Image | null): Image {
2121
}
2222

2323
const ssimMap = new Image(ssim.ssimMap.width, ssim.ssimMap.height, {
24-
colorModel: ImageColorModel.GREY,
24+
colorModel: 'GREY',
2525
data,
2626
});
2727

demo/components/testFunctions/testCannyEdge.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertBinaryToGrey, Image, ImageColorModel } from '../../../src';
1+
import { convertBinaryToGrey, Image } from '../../../src';
22

33
/**
44
* Detect the edges in the image using Canny edge detection
@@ -7,7 +7,7 @@ import { convertBinaryToGrey, Image, ImageColorModel } from '../../../src';
77
* @returns The treated image.
88
*/
99
export function testCannyEdge(image: Image): Image {
10-
let result = image.convertColor(ImageColorModel.GREY);
10+
let result = image.convertColor('GREY');
1111
result = result.gaussianBlur({ size: 7, sigma: 4 });
1212
const edges = result.cannyEdgeDetector({
1313
lowThreshold: 0.08,
@@ -24,13 +24,13 @@ export function testCannyEdge(image: Image): Image {
2424
* @returns The treated image.
2525
*/
2626
export function testCannyEdgeOverlay(image: Image): Image {
27-
let result = image.convertColor(ImageColorModel.GREY);
27+
let result = image.convertColor('GREY');
2828
const edges = result.cannyEdgeDetector({
2929
lowThreshold: 0.08,
3030
highThreshold: 0.1,
3131
});
32-
let greyEdges = edges.convertColor(ImageColorModel.GREY);
33-
greyEdges = greyEdges.convertColor(ImageColorModel.RGBA);
32+
let greyEdges = edges.convertColor('GREY');
33+
greyEdges = greyEdges.convertColor('RGBA');
3434
greyEdges = greyEdges.invert();
3535
for (let row = 0; row < image.height; row++) {
3636
for (let column = 0; column < image.width; column++) {

demo/components/testFunctions/testColorRois.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Image, ImageColorModel } from '../../../src';
2-
import { fromMask, RoisColorMode, colorRois } from '../../../src/roi';
3-
import { RoiKind } from '../../../src/roi/getRois';
1+
import { Image } from '../../../src';
2+
import { fromMask, colorRois } from '../../../src/roi';
43

54
/**
65
* Make a mask out of the image and detect all ROIs. Returns only the white ROIs on a black background.
@@ -9,19 +8,19 @@ import { RoiKind } from '../../../src/roi/getRois';
98
* @returns The treated image.
109
*/
1110
export function testColorRois(image: Image): Image {
12-
const grey = image.convertColor(ImageColorModel.GREY);
11+
const grey = image.convertColor('GREY');
1312
const mask = grey.threshold();
1413

1514
const roiMapManager = fromMask(mask);
1615

1716
let colorImage = colorRois(roiMapManager, {
18-
roiKind: RoiKind.WHITE,
19-
mode: RoisColorMode.RAINBOW,
17+
roiKind: 'white',
18+
mode: 'rainbow',
2019
});
2120

2221
// create a black image
2322
const black = new Image(image.width, image.height, {
24-
colorModel: ImageColorModel.RGBA,
23+
colorModel: 'RGBA',
2524
});
2625
// overlay ROIs on the black image
2726
black.fill([0, 0, 0, 255]);

demo/components/testFunctions/testCopyTo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Image, ImageColorModel } from '../../../src';
1+
import { Image } from '../../../src';
22

33
/**
44
* Copy a black and a red square to the source image.
@@ -13,8 +13,8 @@ export function testCopyTo(image: Image): Image {
1313
column: image.width / 2,
1414
},
1515
});
16-
let blackSquare = new Image(50, 50, { colorModel: ImageColorModel.RGBA });
17-
let redSquare = new Image(150, 150, { colorModel: ImageColorModel.RGBA });
16+
let blackSquare = new Image(50, 50, { colorModel: 'RGBA' });
17+
let redSquare = new Image(150, 150, { colorModel: 'RGBA' });
1818
redSquare.fillChannel(0, 255);
1919
redSquare.fillAlpha(100);
2020
result = blackSquare.copyTo(result, {

demo/components/testFunctions/testCrop.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DerivativeFilters, Image, ImageColorModel } from '../../../src';
1+
import { Image } from '../../../src';
22
// options
33
const cropImageRatio = 2; // defines the size of the cropped image
44
const interval = 2; // defines the speed
@@ -36,10 +36,10 @@ export function testCropBounce(image: Image): Image {
3636
});
3737
const grey = cropped.grey();
3838
const derivative = grey.derivativeFilter({
39-
filter: DerivativeFilters.PREWITT,
39+
filter: 'prewitt',
4040
});
4141

42-
const rgba = derivative.convertColor(ImageColorModel.RGBA);
42+
const rgba = derivative.convertColor('RGBA');
4343

4444
return rgba.copyTo(image, { origin: { row, column } });
4545
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DerivativeFilters, Image, ImageColorModel } from '../../../src';
1+
import { Image } from '../../../src';
22

33
/**
44
* Apply a derivative filter to the source image.
@@ -7,6 +7,6 @@ import { DerivativeFilters, Image, ImageColorModel } from '../../../src';
77
* @returns The treated image.
88
*/
99
export function testDerivativeFilter(image: Image): Image {
10-
image = image.convertColor(ImageColorModel.GREY);
11-
return image.derivativeFilter({ filter: DerivativeFilters.PREWITT });
10+
image = image.convertColor('GREY');
11+
return image.derivativeFilter({ filter: 'prewitt' });
1212
}

demo/components/testFunctions/testExtract.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { fromMask, Image, ImageColorModel } from '../../../src';
2-
import { RoiKind } from '../../../src/roi/getRois';
1+
import { fromMask, Image } from '../../../src';
32

43
/**
54
* Extract the pixels of a mask from the image.
@@ -9,12 +8,12 @@ import { RoiKind } from '../../../src/roi/getRois';
98
*/
109
export function testExtract(image: Image): Image {
1110
const background = new Image(image.width, image.height, {
12-
colorModel: ImageColorModel.RGBA,
11+
colorModel: 'RGBA',
1312
});
1413

1514
background.fill([0, 255, 0, 255]);
1615

17-
const grey = image.convertColor(ImageColorModel.GREY);
16+
const grey = image.convertColor('GREY');
1817
const mask = grey.threshold();
1918

2019
const extracted = image.extract(mask);
@@ -28,11 +27,11 @@ export function testExtract(image: Image): Image {
2827
* @returns - The extracted ROI.
2928
*/
3029
export function testExtractRoi(image: Image): Image {
31-
const grey = image.convertColor(ImageColorModel.GREY);
30+
const grey = image.convertColor('GREY');
3231
const mask = grey.threshold();
3332

3433
const roiMapManager = fromMask(mask);
35-
const rois = roiMapManager.getRois({ kind: RoiKind.WHITE, minSurface: 100 });
34+
const rois = roiMapManager.getRois({ kind: 'white', minSurface: 100 });
3635

3736
const roiMask = rois[0].getMask();
3837

demo/components/testFunctions/testGetBorderPoints.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { fromMask, Image, ImageColorModel, Mask } from '../../../src';
2-
import { RoiKind } from '../../../src/roi/getRois';
1+
import { fromMask, Image, Mask } from '../../../src';
32
/**
43
* Paint the border of the larger black ROI on the image.
54
* @param image The image to process
65
* @returns The processed image.
76
*/
87
export function testGetBorderPoints(image: Image): Image {
9-
const grey = image.convertColor(ImageColorModel.GREY);
8+
const grey = image.convertColor('GREY');
109
const mask = grey.threshold();
1110

1211
const roiMapManager = fromMask(mask);
1312

14-
const rois = roiMapManager.getRois({ kind: RoiKind.BLACK });
13+
const rois = roiMapManager.getRois({ kind: 'black' });
1514

1615
const roi = rois.sort((a, b) => b.surface - a.surface)[0];
1716

demo/components/testFunctions/testGetConvexHull.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { fromMask, Image, ImageColorModel } from '../../../src';
2-
import { RoiKind } from '../../../src/roi/getRois';
1+
import { fromMask, Image } from '../../../src';
32

43
/**
54
* Draw the convex Hull polygon of the largest ROI in green and display the filled ROI in purple.
@@ -8,11 +7,11 @@ import { RoiKind } from '../../../src/roi/getRois';
87
* @returns The image with the convex Hull.
98
*/
109
export function testGetConvexHull(image: Image): Image {
11-
const grey = image.convertColor(ImageColorModel.GREY);
10+
const grey = image.convertColor('GREY');
1211
const mask = grey.threshold({ threshold: 35 });
1312
const roiMapManager = fromMask(mask);
1413

15-
const rois = roiMapManager.getRois({ kind: RoiKind.BLACK });
14+
const rois = roiMapManager.getRois({ kind: 'black' });
1615

1716
const roi = rois.sort((a, b) => b.surface - a.surface)[0];
1817
if (roi) {

0 commit comments

Comments
 (0)