-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.ts
49 lines (33 loc) · 1.09 KB
/
map.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Bitmap from './bitmap.ts';
import StructuralElement from './structural.ts';
import dilate from './dilate.ts';
import { normalize } from './normalize.ts';
/**
* Funkcja zwraca mapę odległości geodezyjnej od zadanego przez
* użytkownika punktu (x, y)
* @param bitmap Obraz wejściowy
* @returns Mapa odległości geodezyjnej od punktu
*/
const makeMap = (bitmap: Bitmap) => {
const input = prompt("Podaj punkt (x,y)");
if(!input)
throw new Error("Nie podano punktu");
const [x, y] = input.trim().split(",").map(val => Number(val));
const mask = StructuralElement.square(3);
mask[1][1] = 0;
let marker = new Bitmap(bitmap.width, bitmap.height);
marker.setMono(x, y, 255);
let distance = 1;
let prevArea = 0;
let newArea = 1;
while(prevArea != newArea) {
marker = dilate(marker, mask, distance);
prevArea = newArea;
newArea = marker.and(bitmap);
distance++;
}
const [min, max] = marker.getMinMax();
normalize(marker, [[1,1], [max,255]]);
return marker;
}
export default makeMap;