Skip to content

Commit

Permalink
Merge pull request #472 from wearepal/bugfix-missing-masking
Browse files Browse the repository at this point in the history
Added missing mask handling to interpolation and segmentation components
  • Loading branch information
paulthatjazz authored Dec 19, 2024
2 parents 3ce1da9 + f927996 commit 6ebb445
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/javascript/modelling/worker/interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function interpolateGrid(input : NumericTileGrid, mask : BooleanTileGrid,
const tile_length = getMedianCellSize(input).length

result.iterate((x, y) => {
if(!mask.get(x, y)) return
switch (type) {
case "NearestNeighbour":
const [n, d] = tree.nearest({x, y}, 1)[0]
Expand Down
17 changes: 13 additions & 4 deletions app/javascript/projects/modelling/components/segment_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { BooleanTileGrid, NumericTileGrid } from "../tile_grid"
import { createXYZ } from "ol/tilegrid"
import { Point } from "ol/geom"
import { Coordinate } from "ol/coordinate"
import { maskFromExtentAndShape } from "../bounding_box"

async function retrieveSegmentationMasks(prompts: string, det_conf: string, clf_conf: string, n_repeats: string, projectProps: ProjectProperties, err: (err: string) => void) : Promise<any[]>{
async function retrieveSegmentationMasks(prompts: string, det_conf: string, clf_conf: string, n_repeats: string, projectProps: ProjectProperties, mask: BooleanTileGrid, err: (err: string) => void) : Promise<any[]>{

const tileGrid = createXYZ()

Expand Down Expand Up @@ -81,8 +82,9 @@ async function retrieveSegmentationMasks(prompts: string, det_conf: string, clf_
projectProps.zoom
)

result.set(featureTileRange.maxX, featureTileRange.minY, true)
confBox.set(featureTileRange.maxX, featureTileRange.minY, pred.confidence)
const maskV = mask.get(featureTileRange.maxX, featureTileRange.minY)
result.set(featureTileRange.maxX, featureTileRange.minY, maskV)
confBox.set(featureTileRange.maxX, featureTileRange.minY, maskV ? pred.confidence : NaN)
})

const predBox = pred.box
Expand Down Expand Up @@ -160,6 +162,13 @@ export class SegmentComponent extends BaseComponent {
const det_conf = node.data.det_conf as string
const cls_conf = node.data.cls_conf as string
const n_repeats = node.data.n_repeats as string
const mask = await maskFromExtentAndShape(
this.projectProps.extent,
this.projectProps.zoom,
this.projectProps.maskLayer,
this.projectProps.maskCQL,
this.projectProps.mask
)

if (this.cache.has(`${prompts}_${cls_conf}%${det_conf}%${n_repeats}`)) {
const result = this.cache.get(`${prompts}_${cls_conf}%${det_conf}%${n_repeats}`)!
Expand All @@ -168,7 +177,7 @@ export class SegmentComponent extends BaseComponent {
outputs['conf'] = result[2]
}else{
let nodeErr = ""
const result = await retrieveSegmentationMasks(prompts, det_conf, cls_conf, n_repeats, this.projectProps, (err) => {
const result = await retrieveSegmentationMasks(prompts, det_conf, cls_conf, n_repeats, this.projectProps, mask, (err) => {
nodeErr = err
})
if (result.length === 0) {
Expand Down

0 comments on commit 6ebb445

Please sign in to comment.