Skip to content
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

feat: Image annotator #1400

Merged
merged 41 commits into from
May 17, 2022
Merged

feat: Image annotator #1400

merged 41 commits into from
May 17, 2022

Conversation

mturoci
Copy link
Collaborator

@mturoci mturoci commented May 4, 2022

Demo

Screen.Recording.2022-05-04.at.3.05.02.PM.mov

Proposed API

/** Rectangle (box) annotation. */
interface ImageAnnotatorRect {
  /** Start X dimension. */
  x1: U
  /** End X dimension. */
  x2: U
  /** Start Y dimension. */
  y1: U
  /** End Y dimension. */
  y2: U
}

/** Defines a particular shape to be used for the annotation. */
interface ImageAnnotatorShape {
  rect: ImageAnnotatorRect
}

/** Image annotator tag. */
interface ImageAnnotatorTag {
  /** An identifying name for this tag. */
  name: Id
  /** Text to be displayed. */
  label: S
  /** HEX or RGB color string used as background for highlighted phrases. */
  color: S
}

/** Create an annotator item with initial selected tags or no tag for plaintext. */
interface ImageAnnotatorItem {
  /** The annotation shape. */
  shape: ImageAnnotatorShape
  /** Tag connected to the highlighted section. */
  tag: S
}

/**
 * Create an image annotator component.
 * 
 * The image annotator component enables user to manually annotate parts of an image.
 */
export interface ImageAnnotator {
  /** An identifying name for this component. */
  name: Id
  /** The image to annotate. */
  image: S
  /** The text annotator's title. */
  title: S
  /** List of tags the user can annotate with. */
  tags: ImageAnnotatorTag[]
  /** Existing annotations if any. */
  items?: ImageAnnotatorItem[]
  /** True if the form should be submitted when the annotator value changes. */
  trigger?: B
  /** The card’s image height. Intrinsic image size is used by default. */
  image_height?: S
}

Returning ImageAnnotatorItem .

@lo5 please have a look at the API - I tried to design it in a way so that we can support multiple shapes (circles/paths) in future as well. Let me know if you see room for improvement though.

Notes

  • Unit tests / docs to be delivered once the API is settled.

cc @dott1718 for shallow feedback based on just video. I expect more detailed feedback after you play around with it in nightly.
Closes #1323

@mturoci mturoci requested a review from lo5 as a code owner May 4, 2022 13:04
@mturoci mturoci requested review from geomodular and mtanco May 4, 2022 13:04
@mturoci mturoci changed the title Image annotator feat: Image annotator May 4, 2022
@dott1718
Copy link

dott1718 commented May 4, 2022

Thank you @mturoci, the component looks great! We will provide more feedback as soon as we can try it out.

@lo5
Copy link
Member

lo5 commented May 11, 2022

Demo looks great 🎸!

It's not clear to me how items and ImageAnnotatorItem, ImageAnnotatorShape, ImageAnnotatorRect are intended to be used. The one example in this PR doesn't use any of them. Maybe that'll help clarify why tag is a string, and why rect is an attribute of ~Shape. It would be good to add another example that show those components in use.

@mturoci
Copy link
Collaborator Author

mturoci commented May 11, 2022

It's not clear to me how items and ImageAnnotatorItem, ImageAnnotatorShape, ImageAnnotatorRect are intended to be used.

I updated the existing example to show predefined annotation. The basic reasoning is:

  • Tag is a string so that we are consistent with tag in ui.text_annotator + there are not many other options.
  • The ImageAnnotatorShape is a bit more tricky, but the overarching goal is to do us a favor and allow for extending the image annotator with other shapes in the future, e.g. circle/paths. I took this approach to be consistent with how we define our table cell types.

@mturoci
Copy link
Collaborator Author

mturoci commented May 11, 2022

@lo5 one more thing that is worth discussing is the image aspect ratio. Since images to be annotated can be various sizes, we have basically 2 options:

  • Display them in their original (intrinsic) size even at the price of scrollbars (in case of overflow).
  • Provide height attr and scale the image accordingly - I went for this option.

Since I chose the second option as it is more UX-friendly, I had to make adjustments to the coordinates based on the aspect ratio so that developers can specify and receive coordinates relative to the original size of their img. Example:

Original img: 100x100 with coordinates 10,10.
Scaled image with height 50px: 50x50 with coordinates translated to 5,5.

The proposed approach makes sense to me, but feel free to point out any alternatives as you see fit.

@lo5
Copy link
Member

lo5 commented May 11, 2022

OK, so if I'm understanding this correctly, ImageAnnotatorItem.tag looks up an existing ImageAnnotatorTag.name to determine the label and color?

@lo5
Copy link
Member

lo5 commented May 11, 2022

The proposed approach makes sense to me, but feel free to point out any alternatives as you see fit.

Your approach sounds good to me.

@mturoci
Copy link
Collaborator Author

mturoci commented May 11, 2022

OK, so if I'm understanding this correctly, ImageAnnotatorItem.tag looks up an existing ImageAnnotatorTag.name to determine the label and color?

That's right.

ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
ui/src/image_annotator.tsx Outdated Show resolved Hide resolved
mturoci and others added 22 commits May 12, 2022 16:05
@mturoci
Copy link
Collaborator Author

mturoci commented May 12, 2022

Thanks for the thorough review @lo5! All the comments were addressed and the branch rebased. Could you please give it one last quick glance and if it looks good to you, we can merge.

@mturoci mturoci merged commit c0c1143 into master May 17, 2022
@mturoci mturoci deleted the feat/issue-1323 branch May 17, 2022 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image annotator component
3 participants