How to draw rect on image/slice at correct position
See original GitHub issueHi,
I’d like to
- Click link to navigate and go to a slice by calling switchToImageByIndex(imageIndex)
- Draw a rectangle on display image(slice)
I’ve done
I can draw by below code but the position of rectangle is incorrect. At first time series display, I click “View slice”, the rect position is incorrect. If I click any button (on header menu), the position of rectangle is moved to new one that as my expected. Please find the attach.
What is my wrong? How can I draw at correct position as my expected one?
I think I need convert the coordinate system but no way. Please help me.
Template.XXX.events({
'click ul li a'(event) {
...
const $element = $('.imageViewerViewport');
$element.on('cornerstoneimagerendered', onImageRendered);
}
})
const onImageRendered = (event, eventData) => {
const detectedSopInstanceUId = Session.get("detectedSopInstanceUId");
const instance = aiUtils.getViewportInstanceInfo();
const currentSopInstanceUid = instance.sopInstanceUid;
// Checl sopId
if (currentSopInstanceUid == detectedSopInstanceUId) {
// Call mark
drawRect();
}
}
function drawRect() {
....
const canvas = activeViewport.querySelector('canvas');
const context = canvas.getContext('2d');
context.beginPath();
// Mark rectangle
context.strokeStyle = 'red';
context.lineWidth = 2;
context.rect(Number(currentPosition.x) - area/4, Number(currentPosition.y) - area/4, area/2, area/2);
// Draw
context.stroke();
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
How to draw rect on image/slice at correct position
Click link to navigate and go to a slice by calling switchToImageByIndex(imageIndex) 2. Draw a rectangle on display image(slice).
Read more >DrawImage fails to position sliced images correctly
Here's a snippet with code adjusting for the bug in CF. My only concern now is that the slices that get square stretched...
Read more >Python PIL | ImageDraw.Draw.rectangle() - GeeksforGeeks
You can use this module to create new images, annotate or retouch existing images, and to generate graphics on the fly for web...
Read more >Draw rectangles and modify stroke options - Adobe Support
Draw a rectangle · Mode: Set a mode for your Rectangle tool — Shape, Path, and Pixels. · Fill: Choose a color to...
Read more >How to draw over a slice via Java - Image.sc Forum
convertToRGB(); BufferedImage bi = ip.getBufferedImage(); Graphics2D g2 = (Graphics2D)bi.getGraphics(); g2.clearRect(0, 0, imp.getWidth(), imp.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@liuchen1393193701, please stop leaving short, unhelpful comments across many issues. If you need assistance, please:
At that point, if you are not receiving the answers you need to resolve your issue, you may want to consider paid support from an expert.
Best of luck ^_^
As a heads up, I have removed some of the less helpful comments.
Hi @dannyrb
I’ve just solved my issues.
I check sopInstanceUid is my expected SopId and current element has no toolData, made rectangleRoi.
toolData = cornerstoneTools.getToolState(element, 'rectangleRoi');
Thank you for your support.