azavea / azavea/loam

Does loam compromise the image quality ?

Open
#128 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
226
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Hey hi, i just i want to know that does loam compromise the image quality,Below i have given code that is used to parse .tif file and return some O/P in object
```
import loam from "loam";
import * as L from "leaflet";
import { v4 as uuidv4 } from "uuid";
loam.initialize("/");
export const CreateLayer = async (files, map) => {
const dataset = await loam.open(files);
const wktDest =
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]';
const smallDataset = await dataset.convert([
"-of",
"GTiff",
"-outsize",
"1000",
"0",
"-r",
"nearest",
]);
dataset.close();
const newDataset = await smallDataset.warp([
"-co",
"PREDICTOR=2",
"-dstnodata",
"0",
"-of",
"GTiff",
"-t_srs",
"EPSG:3857",
"-r",
"near",
]);
smallDataset.close();
const width = await newDataset.width();
const height = await newDataset.height();
const geoTransform = await newDataset.transform();
const wktSource = await newDataset.wkt();
const corners = [
[0, 0],
[width, 0],
[width, height],
[0, height],
];
const geoCorners = corners.map((coords) => {
const x = coords[0];
const y = coords[1];
return [
geoTransform[0] + geoTransform[1] * x + geoTransform[2] * y,
geoTransform[3] + geoTransform[4] * x + geoTransform[5] * y,
];
});
const wgs84GeoCornersGdal = await loam.reproject(
wktSource,
wktDest,
geoCorners
);
const wgs84GeoCorners = wgs84GeoCornersGdal.map((coords) => [
coords[1],
coords[0],
]);
const pngDataset = await newDataset.convert(["-of", "PNG","-co", "COMPRESSION=deflate","-co", "PREDICTOR=2",]);
const imageBytes = await pngDataset.bytes();
const outputBlob = new Blob([imageBytes], { type: "image/png" });
const imageURL = window.URL.createObjectURL(outputBlob);
const imageOverlay = L.imageOverlay(imageURL, wgs84GeoCorners);
const imageBounds = imageOverlay.getBounds();
// const zoom = map.target.getBoundsZoom(imageBounds);
const center = imageBounds.getCenter();
const TiffParsedata = {
id: uuidv4(),
url: `${imageURL}`,
bounds: wgs84GeoCorners,
imageBounds: imageBounds,
center: center,
};
let center1 = [center.lat, center.lng];
// map.target.setView(center1, zoom);
return TiffParsedata;
};
```
The out put of this above method will return **imageUrl**,**Bounds**,**ImageBounds** and **Center** so here image url is being overlayed on react-leaflet map for further implement, but the image is being generated by loam **will have poor quality then its original** (original image size can be around 200mb to 600mb .tif file) my question is there any way that loam can persist image original size as it is,do we have any work arounds here

I have tried this below code to improve the image quality but no use !
` const pngDataset = await newDataset.convert(["-of", "PNG","-co", "COMPRESSION=deflate","-co", "PREDICTOR=2",]);`
Please let us know if there are any possibility. Thanks you...

_Originally posted by @syncthreads-sammith in https://github.com/azavea/loam/issues/120#issuecomment-1867372479_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the CreateLayer entry point and trace the convert, warp, and PNG conversion options used for the TIFF. Compare the source dimensions and output quality, especially after -outsize 1000 and reprojection. Done means identifying whether the quality loss is expected and documenting or correcting a supported way to preserve the required image quality.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
computer-graphics, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.