question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to draw rect on image/slice at correct position

See original GitHub issue

Hi,

I’d like to

  1. Click link to navigate and go to a slice by calling switchToImageByIndex(imageIndex)
  2. 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(); 
}

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
dannyrbcommented, May 8, 2019

@liuchen1393193701, please stop leaving short, unhelpful comments across many issues. If you need assistance, please:

  • Create a new GitHub issue in the appropriate repository
  • Describe what you have already tried and your results
  • If relevant, include a minimal reproduction or example

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.

1reaction
lam0620commented, May 20, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found