-
Couldn't load subscription status.
- Fork 0
fix: improve image dataset handling #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50391e1
feat: add imageLoader script
EscapedGibbon b5362a6
feat: add image loader plugin to docusaurus
EscapedGibbon 90ec294
Merge remote-tracking branch 'origin/main' into 161-improve-image-dat…
EscapedGibbon 2347209
refactor: move default images to js file
EscapedGibbon b14c65e
fix: minor updates and fixes
EscapedGibbon a4187a6
feat: add demo images and json with data
EscapedGibbon 7559c15
refactor: make filepaths' logic cleaner
EscapedGibbon 07984cd
fix: resolve conversations
EscapedGibbon 7326707
refactor: resolve conversations
EscapedGibbon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| import { fetchURL, write } from 'image-js'; | ||
|
|
||
| import { defaultImages, defaultMasks } from './imageDataset.mjs'; | ||
|
|
||
| const __dirname = import.meta.dirname; | ||
|
|
||
| export async function imageLoader() { | ||
| const demoImagesDir = 'demoImages'; | ||
| const staticDir = 'static'; | ||
|
|
||
| const imageData = { masks: [], images: [] }; | ||
| try { | ||
| // Create static directory if it doesn't exist | ||
| const staticPath = path.join(__dirname, staticDir, demoImagesDir); | ||
|
|
||
| if (!fs.existsSync(staticPath)) { | ||
| fs.mkdirSync(staticPath, { recursive: true }); | ||
| } | ||
|
|
||
| const images = await Promise.all( | ||
| defaultImages.map((imageDataUrl) => fetchURL(imageDataUrl.value)), | ||
| ); | ||
|
|
||
| for (let i = 0; i < images.length; i++) { | ||
| const image = images[i]; | ||
| const imageDataUrl = defaultImages[i]; | ||
| const imageTitle = getFilename(imageDataUrl.value); | ||
| const imagePath = path.join( | ||
| __dirname, | ||
| staticDir, | ||
| demoImagesDir, | ||
| 'images', | ||
| imageTitle, | ||
| ); | ||
| write(imagePath, image, { recursive: true }); | ||
| // Keeping object structure for compatibility | ||
| imageData.images.push({ | ||
| type: 'url', | ||
| imageType: 'image', | ||
| label: `${imageDataUrl.label} (${image.width}x${image.height})`, | ||
| value: `/${demoImagesDir}/images/${imageTitle}`, | ||
| }); | ||
| } | ||
|
|
||
| const masks = await Promise.all( | ||
| defaultMasks.map((maskDataUrl) => fetchURL(maskDataUrl.value)), | ||
| ); | ||
|
|
||
| for (let i = 0; i < masks.length; i++) { | ||
| const mask = masks[i]; | ||
| const maskDataUrl = defaultMasks[i]; | ||
| const maskTitle = getFilename(maskDataUrl.value); | ||
| const maskPath = path.join( | ||
| __dirname, | ||
| staticDir, | ||
| demoImagesDir, | ||
| 'masks', | ||
| maskTitle, | ||
| ); | ||
| write(maskPath, mask, { recursive: true }); | ||
| // Keeping object structure for compatibility | ||
| imageData.masks.push({ | ||
| type: 'url', | ||
| imageType: 'mask', | ||
| label: `${maskDataUrl.label} (${mask.width}x${mask.height})`, | ||
| value: `/${demoImagesDir}/masks/${maskTitle}`, | ||
| }); | ||
| } | ||
| // Write data about newly created files. | ||
| const outputPath = path.join(__dirname, 'src/demo/contexts/demo/generated'); | ||
| if (!fs.existsSync(outputPath)) { | ||
| fs.mkdirSync(outputPath, { recursive: true }); | ||
| } | ||
| fs.writeFileSync( | ||
| `${outputPath}/imageData.json`, | ||
| JSON.stringify(imageData, null, 2), | ||
| ); | ||
| } catch (error) { | ||
| throw new Error(`Error in imageLoader: ${error.message}`); | ||
| } | ||
|
|
||
| return imageData; | ||
| } | ||
| // Returns only filename with extension. | ||
| function getFilename(filepath) { | ||
| return filepath.replace(/^.*[\\/]/, ''); | ||
| } | ||
| await imageLoader(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| const standardUrl = 'https://demo-dataset.image-js.org/standard'; | ||
| const standardMaskUrl = 'https://demo-dataset.image-js.org/standard_mask'; | ||
| const morphologyMaskUrl = 'https://demo-dataset.image-js.org/morphology_mask'; | ||
|
|
||
| export const defaultImages = [ | ||
| { | ||
| value: `${standardUrl}/jellybeans.png`, | ||
| label: 'Jelly beans ', | ||
| imageType: 'image', | ||
| }, | ||
| { | ||
| value: `${standardUrl}/female.png`, | ||
| label: 'Female', | ||
| imageType: 'image', | ||
| }, | ||
| { | ||
| value: `${standardUrl}/femaleBellLabs.png`, | ||
| label: 'Female from Bell Labs ', | ||
| imageType: 'image', | ||
| }, | ||
| { | ||
| value: `${standardUrl}/house.png`, | ||
| label: 'House', | ||
| imageType: 'image', | ||
| }, | ||
| { | ||
| value: `${standardUrl}/mandrill.png`, | ||
| label: 'Mandrill', | ||
| imageType: 'image', | ||
| }, | ||
| { | ||
| value: `${standardUrl}/peppers.png`, | ||
| label: 'Peppers', | ||
| imageType: 'image', | ||
| }, | ||
|
|
||
| { | ||
| value: `${standardUrl}/barbara.jpg`, | ||
| label: 'Barbara', | ||
| imageType: 'image', | ||
| }, | ||
|
|
||
| { | ||
| value: `${standardUrl}/boat.png`, | ||
| label: 'Standard boat', | ||
| imageType: 'image', | ||
| }, | ||
| { | ||
| value: `${standardUrl}/male.png`, | ||
| label: 'Male', | ||
| imageType: 'image', | ||
| }, | ||
| { | ||
| value: `${standardUrl}/airport.png`, | ||
| label: 'Airport', | ||
| imageType: 'image', | ||
| }, | ||
| ]; | ||
|
|
||
| export const defaultMasks = [ | ||
| { | ||
| type: 'url', | ||
| value: `${morphologyMaskUrl}/circles.png`, | ||
| label: 'Circles', | ||
| imageType: 'mask', | ||
| }, | ||
| { | ||
| value: `${morphologyMaskUrl}/shapes.png`, | ||
| label: 'Shapes', | ||
| imageType: 'mask', | ||
| }, | ||
| { | ||
| value: `${morphologyMaskUrl}/star.png`, | ||
| label: 'Star', | ||
| imageType: 'mask', | ||
| }, | ||
| { | ||
| value: `${standardMaskUrl}/house.png`, | ||
| label: 'House', | ||
| imageType: 'mask', | ||
| }, | ||
| { | ||
| value: `${standardMaskUrl}/mandrill.png`, | ||
| label: 'Mandrill', | ||
| imageType: 'mask', | ||
| }, | ||
| { | ||
| value: `${standardMaskUrl}/peppers.png`, | ||
| label: 'Peppers', | ||
| imageType: 'mask', | ||
| }, | ||
|
|
||
| { | ||
| value: `${standardMaskUrl}/barbara.png`, | ||
| label: 'Barbara', | ||
| imageType: 'mask', | ||
| }, | ||
| { | ||
| value: `${standardMaskUrl}/boat.png`, | ||
| label: 'Standard boat', | ||
| imageType: 'mask', | ||
| }, | ||
|
|
||
| { | ||
| value: `${standardMaskUrl}/male.png`, | ||
| label: 'Male', | ||
| imageType: 'mask', | ||
| }, | ||
| ]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.