|
1 | 1 | import { resolve } from "path";
|
| 2 | +import { Region } from "../../region.class"; |
2 | 3 | import { ImageProcessor } from "./image-processor.class";
|
3 | 4 | import { ImageReader } from "./image-reader.class";
|
4 | 5 |
|
@@ -37,3 +38,45 @@ describe("ImageProcessor", () => {
|
37 | 38 | expect(mat.empty).toBeFalsy();
|
38 | 39 | });
|
39 | 40 | });
|
| 41 | + |
| 42 | +describe("ImageProcessor with ROI", () => { |
| 43 | + it("negative left or top values are updated to 0", async () => { |
| 44 | + // GIVEN |
| 45 | + const imageReader = new ImageReader(); |
| 46 | + const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
| 47 | + const image = await imageReader.load(imagePath); |
| 48 | + |
| 49 | + // WHEN |
| 50 | + const mat = await ImageProcessor.fromImageWithoutAlphaChannel( |
| 51 | + image, |
| 52 | + new Region(-100, -100, 10, 10) |
| 53 | + ); |
| 54 | + |
| 55 | + // THEN |
| 56 | + expect(image.hasAlphaChannel).toBeFalsy(); |
| 57 | + expect(mat.channels).toEqual(3); |
| 58 | + expect(mat.rows).toEqual(10); |
| 59 | + expect(mat.cols).toEqual(10); |
| 60 | + expect(mat.empty).toBeFalsy(); |
| 61 | + }); |
| 62 | + |
| 63 | + it("values bigger than the input are updated to width and height", async () => { |
| 64 | + // GIVEN |
| 65 | + const imageReader = new ImageReader(); |
| 66 | + const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
| 67 | + const image = await imageReader.load(imagePath); |
| 68 | + |
| 69 | + // WHEN |
| 70 | + const mat = await ImageProcessor.fromImageWithoutAlphaChannel( |
| 71 | + image, |
| 72 | + new Region(10, 10, image.width * 2, image.height * 2) |
| 73 | + ); |
| 74 | + |
| 75 | + // THEN |
| 76 | + expect(image.hasAlphaChannel).toBeFalsy(); |
| 77 | + expect(mat.channels).toEqual(3); |
| 78 | + expect(mat.rows).toEqual(image.height - 10); |
| 79 | + expect(mat.cols).toEqual(image.width - 10); |
| 80 | + expect(mat.empty).toBeFalsy(); |
| 81 | + }); |
| 82 | +}); |
0 commit comments