How to add a color or calibration bar - dm-script

I would like to append a color bar to my image to indicate what value corresponds to which color.
Something similar to the calibration bar in ImageJ.
Thank you for your help

What you are looking for is the "Intensity bar".
Example script right from the F1 help documenation:
image img := RealImage("Test",4,512,512)
img = itheta
img.ShowImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
number kSCALEBAR = 31
number kINTENSITYBAR = 33
component scalebar = NewComponent( kSCALEBAR, 450, 100, 480, 300 )
disp.ComponentAddChildAtEnd( scalebar )
component intbar = NewComponent( kINTENSITYBAR, 50, 400, 450, 490 )
disp.ComponentAddChildAtEnd( intbar )

Related

With several ROIs in an image, how can I send the ROI to the back

When I have several ROIs in an image, they can overlap and sometimes the smaller one gets lost behind the bigger one. However, one of the is on "top" and the other is "below." I have the ID of the ROI, but I am missing the command ROI_ID.ROISendToBack() or similar.
Any trick available?
Thanks!
The order of ROIs on a display can not be the property of an individual ROI, but it is a property of the thing 'containing' the ROIs. That's why you search for the command at the wrong place. It is not a command of the ROI object, but of the ImageDisplay object.
Each ImageDisplay contains a "list" of its ROIs and you want to change the order in that list.
The commands for specifying the "order" of ROIs on an ImageDisplay are
There is no command to "move" a ROI, but you can simple remove and re-add it.
image img := RealImage( "Dummy",4, 350, 350)
img = iradius
img.ShowImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
ROI roi1 = NewROI()
roi1.ROISetRectangle( 100, 100, 200, 200 )
roi1.ROISetVolatile(0)
roi1.ROISetColor(1,0,0)
roi1.ROISetDrawFilled(1)
roi1.ROISetFillProperties(0.2,0.1,0,0)
ROI roi2 = NewROI()
roi2.ROISetRectangle( 125, 125, 225, 225 )
roi2.ROISetVolatile(0)
roi2.ROISetColor(0,1,0)
roi2.ROISetDrawFilled(1)
roi2.ROISetFillProperties(0.2,0,0.1,0)
ROI roi3 = NewROI()
roi3.ROISetRectangle( 150, 150, 250, 250 )
roi3.ROISetVolatile(0)
roi3.ROISetColor(0,0,1)
roi3.ROISetDrawFilled(1)
roi3.ROISetFillProperties(0.2,0,0,0.1)
disp.ImageDisplayAddROI( roi1 )
disp.ImageDisplayAddROI( roi2 )
disp.ImageDisplayAddROI( roi3 )
OKDialog( "Now send blue to the bottom" )
disp.ImageDisplayDeleteROI( roi3 )
disp.ImageDisplayAddROIAtBeginning( roi3 )
OKDialog( "Now send red to front" )
disp.ImageDisplayDeleteROI( roi1 )
disp.ImageDisplayAddROIAtEnd( roi1 )

The code/command to determine/change the length/height ratio of scale bar?

I would like to adjust the length/height ratio of the scale bar in an image by the DM scripting. As the following code shown, I can adjust the font size by changing "scalebar.componentsetfontinfo("Microsoft Sans Serif", 0, fontsize)", but I do not know how to change the shape (length/height ratio) of rectangle which constitute to the scale bar. Is there any code/command can achieve this? Thanks,
image front:=getfrontimage()
imagedisplay imgdisp=front.imagegetimagedisplay(0)
number nobar=imgdisp.componentcountchildrenoftype(31)
number fontsize=20
imgdisp.applydatabar(0)
component scalebar=imgdisp.componentgetnthchildoftype(31,0)
scalebar.componentsetfontinfo("Microsoft Sans Serif", 0, fontsize)
scalebar.componentsetdrawingmode(1)
When you select a scalebar, you will notice the green points showing that component's rectangle.
You control that rectangle like you control any component rectangle:
number kScaleBar = 31
image img := GetFrontImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
component scaleBar = disp.ComponentGetNthChildOfType( kScaleBar, 0 )
number t,l,b,r
scaleBar.ComponentGetRect(t,l,b,r)
Result("\n Current rect: [" + t + "/" + l + "/" + b + "/" + r )
number sx, sy
img.GetSize( sx, sy )
// Set centered half at bottom
l = sx*1/4
r = sx*3/4
t = sy*17/20
b = sy*19/20
scaleBar.ComponentSetRect(t,l,b,r)
Note, that you can not explicitly specify the length of the scalebar, it will always "snap" to a meaningful fraction within the boundary box, depending on the image calibration.
Setting the bounding rect will also override the font-size, while setting the font-size will override the boundary rect's height.

How can I select a subarea of an image with mouse and make it a new image?

I want to get some subarea of an image and make it a new image, and then execute further functions on it.
How can I use mouse to select a subarea of an image?
I know img[] could get the subarea of img, but I need some function by which I can interact with img. I mean, I want to get a WYSIWYG effect.
Is there any commands available, or is there any methods of ROI capable?
There different ways to do what you want in a script: You could ask the user to place an ROI and then use the [] to address this area. If you want to get a new image from this selection (CTRL + C and CTRL + SHIFT + V without scripting) you would write:
ShowImage( ImageClone( img[] ) )orimg[].ImageClone().ShowImage()
If you want to place a ROI for the user, you can used SetSelection() for a simple, rectangle, volatile ROI, or you use the full ROI commands like in this example:
image img := RealImage( "Test", 4, 256, 256 ) // create image
img.ShowImage() // show the image (so that it has a display)
imageDisplay disp = img.ImageGetImageDisplay(0) // Get the 'display' of an image
ROI myR = NewRoi() // create ROI
myR.ROISetRectangle( 110, 120, 130, 140 ) // Make it a rectangle of given area
myR.ROISetVolatile( 0 ) // make it non-volatile
myR.ROISetLabel( "Selection" ) // give it a label
myR.ROISetColor( 0, 1, 0 ) // make it green
disp.ImageDisplayAddROI( myR ) // add it to the display
A full list of ROI commands can be found in the following section of the F1 help documentation:

Xcode UILabel upside down

I want to have a label which should be displayed upside down. That means after creating the label I want to turn it around 90 degrees. That works but now the label is anywhere. I don't know HOW the label is rotated. Maybe one could help me. The code is the following:
let label = CreatorClass.createLabelWithFrame(CGRect(x: 10, y: 10, width: 150, height: 15), text: "aString", size: 12.0, bold: false, textAlignment: .Left, textColor: UIColor.whiteColor(), addToView: self)
label.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
CreatorClass creates a label and add it to a certain view (it adds to self because this code is called in a subclass of UIView). Actually it's self-explanatory I think.
you label rotate around its center, that means:
You label rotate around : x = 10 + 75 = 85
y = 10 + 7.5 = 17.5
This is also the center of the new position, what has a width of 15.0 and height of 150;
The new rect of your view, after the transfer is:
x = 85 - 7.5 = 77.5;
y = 17.5 - 75 = -57.5;
width = 15 , height = 150.
It could be out of the self bounds.
You might want to go back your label to its init position, only need to put it to init position:
label.frame = CGRect(x: 10, y: 10, width: 15, height: 150)

Calculte new width and height of the video based on the original width, height and ratio

After searching through - I wasn't able to find the answer so I'll give it a shot here.
I need to resize desktop video in order to feet it on mobile screen, let's say original width of the video was 1915 and original height was 1075, I calculated aspect ratio:
aspectRatio = (width/height); aspectRatio = 1.78;
Now my mobile screen resolution is: height = 1609, width = 1080.
How can I properly resize my video in order to keep the same aspect ratio??
Thank you
aspectRatio = (width/height)
You always want aspectRatio to be 1.78, if you want to prevent stretching or cropping.
And, the max new height is 1609 and the max new width is 1080, so:
1.78 = (1080/height)
height = 1080/1.78 = 606.74...
OR
1.78 = (width/1609)
width = 1.78*1609 = 2864.02...
So, you can have 1080x606.74 (which fits on screen), or 2864.02x1609 (which doesn't fit).
So, your answer is 1080x606.74...
Let's original dimensions are Wo, Ho, and target screen dimensions are Wt, Ht.
Rectangle with predetermined aspect will fit vertically if ratio of target and initial heights less than ratio of its widths, and will fit horizontally otherwise:
Coeff = Min(Wt/Wo, Ht/Ho)
W_Result = Wo * Coeff
H_Result = Ho * Coeff
or
if (Wt * Ho < Ht * Wo) then
W_Result = Wt
H_Result = Ho * Wt / Wo
else
W_Result = Wo * Ht / Ho
H_Result = Ht