Published
Edited
Jul 8, 2020
Insert cell
md`# Loading local image files examples`
Insert cell
md`## Load all files in folder`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ids = ['swv', 'sws', 'sbo', 'sto', 'swe'];
Insert cell
Insert cell
comparision = html `<div id="comparision" class="container"></div>`
Insert cell
function setCanvas(id, caseNo, sliceNo, addCheckbox) {
return html`<div style="display: flex; align-items: center">
${addCheckbox ? html`<input type="checkbox" name="selectScan" data-id=${ id+'/'+caseNo+'/'+sliceNo }/>` : null}
<canvas id=${id} class="scan"></canvas>
<div>`
}
Insert cell
loadImage = function(subDir, caseNo, sliceNo) {
if (multiFileDict[subDir][caseNo] != undefined &&
multiFileDict[subDir][caseNo][sliceNo] != undefined) {
var file = multiFileDict[subDir][caseNo][sliceNo].file;
if (file != undefined) {
return file;
}
}
}
Insert cell
{
sample(loadImage("images", caseNo, sliceNo), loadImage("segmentations_without_variations", caseNo, sliceNo), 'swv');
sample(loadImage("images", caseNo, sliceNo), loadImage("segmentations_with_shifts_5", caseNo, sliceNo), 'sws');
sample(loadImage("images", caseNo, sliceNo), loadImage("segmentations_bottom_over_under_segment_10", caseNo, sliceNo), 'sbo')
sample(loadImage("images", caseNo, sliceNo), loadImage("segmentations_top_over_under_segment_10", caseNo, sliceNo), 'sto')
sample(loadImage("images", caseNo, sliceNo), loadImage("segmentations_with_erosion_dilation_5", caseNo, sliceNo), 'swe')
}
Insert cell
function compare(){
const checkboxes = Array.from(document.getElementsByName('selectScan'))
const selected = checkboxes.filter(c => c.checked).map(ch => ch.dataset.id)
console.log('selected', selected)
getSelectedCanvas(selected)
}
Insert cell
function getSelectedCanvas(selectedCanvas) {
selectedCanvas.map(canvas => {
const canvasData = canvas.split("/"); // To separate id, caseNo and SliceNo
sample(loadImage("images", canvasData[1], canvasData[2]), loadImage("segmentations_without_variations", canvasData[1], canvasData[2]), 'selected'+canvasData[0]);
const canvasToCompare = setCanvas('selected'+canvasData[0], canvasData[1], canvasData[2], false)
const canvasContainer = document.getElementById('comparision');
canvasContainer.appendChild(canvasToCompare)
})
}
Insert cell
Insert cell
Insert cell
html = (await require("htl@0.2")).html
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more