I have to segment a few things in a dataset I have (.nrrd-file) by drawing a rectangle around the area of interest and saving the segments (also as .nrrd-files).
I tried everything in the Segmentation-Tool that comes with MITK but I cannot seem to find a way to draw rectangles. I also tried to do some key combos (like holding shift, ctrl or alt) while drawing but in vain.
I know I can use the Measurement-Tool to select rectangles and save them (as .pf-files), but using that I'd have to write a some code to convert those selected rectangles into rectangle segmentations later on.
Does anyone know whether there's a possibility (that I didnt find yet) to draw rectangles in the Segmentation tool, or some other way so there's no need to write a workaround?
You can use the Image Cropper plugin in MITK 2016.11 for rectangular image masking and cropping (scissors icon).
Open the plugin, select your image in the Data Manager and click on the New button in the plugin to create a bounding object. You can modify the rectangular bounding shape in the render windows by dragging its red handles. You can move the whole shape by hovering over the bounding shape (it will turn green), click, and than drag.
Click on the Mask button if you want to get an image with the same dimensions in which all pixels outside the bounding shape are set to a user defined value (see the Advanced settings in the plugin). Click on the Crop button otherwise.
Note that you can always press F1 in any active MITK plugin to open a help page with detailed instructions.
Related
I am new to C++,Qt and Visual Studio and this is my first post on Stack Overflow.
I apologize in advance if this is a repeated question, I tried searching for a similar question but couldn't find one. Let me know if this is a repeated question and I will delete it.
I am trying to create a line plot using QWidget::paintEvent(). The line plot I am drawing is actually a QPainterPath. I want to detect when the mouse hovers over my line plot and so I create a small rectangle where my mouse cursor is and detect when this rectangle intersects with my line plot using bool QPainterPath::intersects() function. The problem is that this function returns true even when my mouse is not exactly over my line plot. In the Image 1 (I am not allowed to embed images yet) my line plot is the thick black curve and the bool QPainterPath::intersects() returns true even when my cursor is over the yellow region. As per the Qt document this is because:
There is an intersection if any of the lines making up the rectangle crosses a part of the path or if any part of the rectangle overlaps with any area enclosed by the path.
There is no way to have a QPainterPath without any enclosed area as Qt only provides two types of fill for QPainterPath: Qt::OddEvenFill or Qt::WindingFill. (To be honest, I find this kind of annoying, since an open path is a series of line segments connected end-to-end, if someone wants to enclose an area they can easily connect the first and last point using either QPainterPath::lineTo() or QPainterPath::moveTo() functions)
Anyway, I decided to get smarter than Qt and drew two extra QPainterPath with pathUp being a few pixels above my line plot and pathDn being a few pixels below my line plot. Image 2 shows these 3 line plots, red one is pathUp, black one is real line plot and green one is pathDn. I thought I coould detect the intersection in the QWidget::mouseMoveEvent() by using the following code:
// cRect: Rectangle at mouse cursor position
if((pathUp.intersects(cRect) && (!pathDn.intersects(cRect))) || ((!pathUp.intersects(cRect)) && pathDn.intersects(cRect)))
{
qDebug() << "Intersects";
}
But this still produces wrong results because now the enclosed area is different, as you can see in Image 3 the green area is an enclosed area of pathDn and red area is the enclosed area of pathUp. The thick black curve is again the line plot that I want to detect my mouse hover on. This enclosed area is not affected by Qt::setFillRule of QPainterPath.
What's even more frustrating is that I tried this technique using QPolygonF instead of QPainterPath on QWidget and the results were exactly the same. I also tried QGraphicsView, there I used QGraphicsPathItem to create my line plot and then used QGraphicsScene::focusItemChanged() signal to detect when I click on my line plot. It again produced the same result of detecting the click when my cursor is over the enclosed area. I do not want to create a custom QGraphicsItem (unless I absolutely have to) just to reimplement it's hoverEnterEvent() and hoverLeaveEvent() method because of the limitations imposed on the boundingRect() of the QGraphicsItem as explained in Qt Docs:
QGraphicsScene expects all items boundingRect() and shape() to remain unchanged unless it is notified. If you want to change an item's geometry in any way, you must first call prepareGeometryChange() to allow QGraphicsScene to update its bookkeeping.
Since I making a plot in real-time the boundingRect() will change quite frequently (> 20 Hz), which will result in an extra computational burden on the software. Is there any way I can solve my problem without creating a custom QGraphicsItem?
P.S. I have been using Stack Overflow for many years whenever I got stuck. I just never made an account here because I never needed to post anything. You guys are the best and I am very happy to be a part of this community!
I am trying to create a simple paint application using Qt Creator. I want to have a rectangular area on QDialog in which I can draw an image using mouse. The image format will be QImage::Format_Mono (Black and white, pixel indexes are either 0 or 1). I will use pixel indexes for simple image processing purpose, which operates on simple 1 and 0 pixel values, so Format_Mono is essential.
Now the application does its job, but the image (painting area) is stuck at left top part (positioned at x=0 and y=0). I want to have rectangular image editor part at any x and y coordinates I want.
To create the image editor I defined a QImage in dialog.h
QImage image;
In constructor of the Dialog I have:
image = QImage(ui->label->size(), QImage::Format_Mono);
image.fill(Qt::black);
As you can see in above code, I have a QLabel named label in my user interface. I want to put the image editor part in that label (or do something similar).
I checked the QImage documentation, but could not find a function to change the position of the image. Or, it would also be good if I could find any other way to put the image (image editor) in QLabel.
What can I do to have that feature in my application?
EDIT: The created image editor part has the same size as the label (as it should be the case), but image editor (QImage) starts at x=0 and y=0 only.
I know this question has been already asked quite some times, but i would like to specify it. I got an image, which displays a circle blue X and I would like to make my own exit button in a Windows application form.
To do that, i added a button in the form and loaded the image on the button. However, the backcolor of the button ruins the image as it is grey. So i have tried:
private: System::Void button1_Paint(System::Object^ sender,
System::Windows::Forms::PaintEventArgs^ e) {
this->TransparencyKey = BackColor;
}
This doesn't work at all (The backcolor is still grey). So i have tried this:
private: System::Void button1_Paint(System::Object^ sender,
System::Windows::Forms::PaintEventArgs^ e) {
this->BackColor = System::Drawing::Color::Transparent;
}
Here i got a message: This control doesn't support transparent colors
Ok, so how am i gonna do this?
thanks
In WPF as well as win32, controls or child windows in general can't have color transparency.
But they can have a non rectangular region. Any shape, including holes.
Use the control's region property to change it's region. There's an example in this link on how to draw a round button.
FYI, pixels that are outside the region are NOT receiving any messages/notifications.
Examples of crazy shaped controls:
Button shaped like a person's head.
Spiral shape.
3 triangles that do not touch each other.
Chess board - every 2nd pixel is transparent.
Also, a region is dynamic, can be changed after object creation, so your button can grow and shrink...
It's also pretty fast.
Limitations:
No alpha blending - either opaque or fully transparent.
I wrote a function (C++/win32) that takes a control and a BMP, both have the same size, scan the BMP for a "tranparent" color (you decide which color) and remove all pixels in that color from the region of the control. This is about half a screen of code.
Set the Background-property to Transparent:
btn->Background = System::Drawing::Color::Transparent;
By the way, don't do this in the Paint-Handler. Instead, do it in the constructor or any initialization function.
Update:
Ok, got it - it's a Windows Forms application. See this C# Windows Form Application Transparent button link for some solutions for your problem.
Another possibility (that I have used in projects before) would be to use a PictureBox instead and listen to the MouseClick-event.
After I rotate a CCLayer, my boundingBox grows, instead of rotating. Perhaps to be expected.
My issue is, I'm relying on a user touch on this layer. When the layer is rotated as in the figure on the bottom of the attached image, the clickable area increases because I'm calling:
if(CGRectContainsPoint(clickableLayer.boundingBox, touchLocation))
This causes an issue because this bounding box after rotation is covering up other things that are also clickable.
How do I only perform an action if the actual layer is touched? I want something to happen when just the green box is clicked, not the boundingBox of the layer.
Thoughts?
You can use CGMutablePathRef to detect transparent part:
Refer my answer in this thread.
Information about How to create CGPath:Here
For more information, Click Here
This thread got me to my answer: http://www.cocos2d-iphone.org/forum/topic/272336
i've implemented a owner draw button into my win32 app (no MFC). The button is a normal 20x20 bitmap (round icon with transparency). The problem is that the button is positioned on a solid background and i can see the buttons gray background (since the bitmap is round). I've tried responding to WM_CTLCOLORBTN with NULL_BRUSH but no luck.. I've tried displaying the button using a bitmap and a ico file but wont budge.. Does anyone know how to solve this problem?
This is my problem, the settings icon should be transparent at the edges (not white/gray)
It sounds like you're trying to make a non-rectangular control.
You could call SetWindowRgn to tell Windows that your control is non-rectangular.
In addition to what #joel's answer, if you want to make some area transperant put a unique color in the area where you want to have transperancy using some image editors (RGB(0xFF,0x00,0xFF)) is mostly used Then use TransperantBlt
You say it's a solid background but your image shows some kind of orange-yellow gradient as a background. If it really was a standard windows button solid color you can load the bitmap with LoadImage using the LR_LOADMAP3DCOLORS or LR_LOADTRANSPARENT. Since you have a gradient you'll have to use a more complicated technique to mask out the bitmap.
http://www.winprog.org/tutorial/transparency.html