Skip to content

Commit d0bd207

Browse files
- ADD: Added download buttons for unskewed and extracted vegetation images.
- FIX: Fixed issues with images smaller than the resize threshold.
1 parent 349ca2a commit d0bd207

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/components/ImageProcessor.vue

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
</figure>
4949
</ImgComparisonSlider>
5050
</div>
51+
<div v-if="ratio !== undefined && unskewedImageSrc && vegetationImageSrc" class="mt-3 d-flex justify-space-between">
52+
<v-btn class="download-button" prepend-icon="mdi-download" text="Download original" @click.prevent.stop.capture="downloadImage(unskewedImageSrc, 'original')" />
53+
<v-btn class="download-button" prepend-icon="mdi-download" text="Download extracted" @click.prevent.stop.capture="downloadImage(vegetationImageSrc, 'extracted')" />
54+
</div>
5155
</div>
5256
</template>
5357

@@ -77,23 +81,32 @@
7781
const p1 = 0.95
7882
const p2 = 0.95
7983
const p3 = 20
80-
let maxRes = 1080
81-
let maxWidth = 1080
84+
let maxRes = 1440
85+
let maxWidth = 1440
8286
let canvas: Canvas | undefined = undefined
8387
let imageDimensions: Dims = { x: 0, y: 0 }
8488
let canvasDimensions: Dims = { x: 0, y: 0 }
8589
const resizeObserver: ResizeObserver = new ResizeObserver(debounceResize)
8690
let lastKnownWidth: number = 0
8791
let timeout: ReturnType<typeof setTimeout>
8892
93+
function downloadImage (imageSrc: string | undefined, text: string) {
94+
if (imageSrc) {
95+
const a = document.createElement('a')
96+
a.href = imageSrc
97+
a.download = `${text}-${sourceImageFile.value?.name}`
98+
a.click()
99+
}
100+
}
101+
89102
function debounceResize () {
90103
if (sourceImageFile.value && wrapper.value?.clientWidth && lastKnownWidth !== wrapper.value?.clientWidth) {
91104
lastKnownWidth = wrapper.value?.clientWidth
92105
93106
canvas?.dispose()
94107
canvas = undefined
95108
polygon.value = undefined
96-
maxWidth = wrapper.value?.clientWidth || 1080
109+
maxWidth = wrapper.value?.clientWidth || 1440
97110
if (polygonCanvas.value) {
98111
polygonCanvas.value.width = 0
99112
polygonCanvas.value.height = 0
@@ -237,6 +250,7 @@
237250
return LensCanvas.createFromBlob(blob)
238251
})
239252
.then(canvas => {
253+
// TODO: Check if this is even necessary, if not just handle the normal image
240254
return distort(canvas, 'Perspective', [points[0].x, points[0].y, 0, 0, points[1].x, points[1].y, canvas.width, 0, points[3].x, points[3].y, 0, canvas.height, points[2].x, points[2].y, canvas.width, canvas.height], {
241255
viewport: { width: canvas.width, height: canvas.height, x: 0, y: 0 },
242256
virtualPixelMethod: VirtualPixelMethod.TRANSPARENT,
@@ -271,10 +285,12 @@
271285
272286
if (width > maxRes || height > maxRes) {
273287
imageDimensions = limitDimensions(width, height, maxRes)
274-
scaledImageSrc.value = await downscale(sourceImageFile.value, imageDimensions.x, imageDimensions.y)
275-
emitter.emit('set-loading', false)
276-
nextTick(() => addPolygon())
288+
} else {
289+
imageDimensions = { x: width, y: height }
277290
}
291+
scaledImageSrc.value = await downscale(sourceImageFile.value, imageDimensions.x, imageDimensions.y)
292+
emitter.emit('set-loading', false)
293+
nextTick(() => addPolygon())
278294
}
279295
}
280296
@@ -286,6 +302,7 @@
286302
const canopeo = image.grey({
287303
algorithm: (r, g, b) => {
288304
// return ((4 * g - 3 * b - r) > 175) ? 255 : 0
305+
// return (2 * g - r - b)/(2 * g + r + b) > 0.1 ? 255 : 0
289306
return ((r / g < p1) && (b / g < p2) && (2 * g - r - b) > p3) ? 255 : 0
290307
},
291308
})
@@ -302,8 +319,8 @@
302319
if (wrapper.value) {
303320
resizeObserver.observe(wrapper.value)
304321
}
305-
maxWidth = wrapper.value?.clientWidth || 1080
306-
maxRes = 1080
322+
maxWidth = wrapper.value?.clientWidth || 1440
323+
maxRes = 1440
307324
})
308325
onBeforeUnmount(() => {
309326
if (wrapper.value) {

src/plugins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function registerPlugins (app: App) {
2323
domain: 'cropgeeks.github.io/spriggles',
2424
hashMode: true,
2525
apiHost: 'https://plausible.hutton.ac.uk',
26-
trackLocalhost: true,
26+
trackLocalhost: false,
2727
},
2828
settings: {
2929
enableAutoPageviews: true,

0 commit comments

Comments
 (0)