Java ImagePlus duplicate(). I do not want to duplicate ROI, but want to duplicate coordinates specified by me

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Java ImagePlus duplicate(). I do not want to duplicate ROI, but want to duplicate coordinates specified by me

SaralaT

Hi Everyone,


I am writing an Micromanager plugin, and right now it is able to take images by camera, and the user places an ROI on the image. Then I would like to save an area slightly larger than the ROI (x,y,width and height given be me). But I am currently trying to use  the below;


public ImagePlus duplicate()
Returns a copy of this image or stack, cropped if there is an ROI.
See Also:
crop(), Duplicator.run(java.lang.String)

This method only duplicates the ROI, and I am unable to input the specific area I would like to duplicate before saving. How can I get around this problem? I do not want to duplicate the ROI.


Thanks a lot in advance!


Best Regards,

Sarala



_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Java ImagePlus duplicate(). I do not want to duplicate ROI, but want to duplicate coordinates specified by me

nanthony
Hi Sarala,

I don't have an answer to your question, but if you don't get an answer here
I would recommend asking at the ImageJ mailing list as I think your issue
has more to do with imagej than micromanager.

Not sure if this helps but it looks like there is a plugin specifically
designed to enlarge ROIs. It's called ROI Enlarger:
https://imagej.nih.gov/ij/developer/api/index.html

--Nick



--
Sent from: http://micro-manager.3463995.n2.nabble.com/


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Java ImagePlus duplicate(). I do not want to duplicate ROI, but want to duplicate coordinates specified by me

JonD
Administrator
In reply to this post by SaralaT
SaralaT wrote
> I am writing an Micromanager plugin, and right now it is able to take
> images by camera, and the user places an ROI on the image. Then I would
> like to save an area slightly larger than the ROI (x,y,width and height
> given be me). But I am currently trying to use  the below;

Try something like this (works as a Beanshell script and augments each
border by 10 pixels):

import ij.IJ;
import ij.ImagePlus;

// change these variables as needed
int extraBorder = 10;

ImagePlus imp = IJ.getImage();
Rectangle oldRoi = imp.getRoi().getBounds();
int newHeight = oldRoi.height + 2*extraBorder;
int newWidth = oldRoi.width + 2*extraBorder;
int newOffsetY = oldRoi.y - extraBorder;
int newOffsetX = oldRoi.x - extraBorder;
imp.setRoi(newOffsetX, newOffsetY, newWidth, newHeight);
IJ.run("Duplicate...", "title");


Jon



--
Sent from: http://micro-manager.3463995.n2.nabble.com/


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Java ImagePlus duplicate(). I do not want to duplicate ROI, but want to duplicate coordinates specified by me

Radek Macháň
Hi Sarala,

See the attached macro which takes an ROI from the image duplicates it and then makes another ROI shifted by a specified number of pixels and duplicates that one as well. Would something analogous to this work for you?

Best wishes,
Radek

On Fri, 2 Nov 2018 at 17:12, JonD <[hidden email]> wrote:
SaralaT wrote
> I am writing an Micromanager plugin, and right now it is able to take
> images by camera, and the user places an ROI on the image. Then I would
> like to save an area slightly larger than the ROI (x,y,width and height
> given be me). But I am currently trying to use  the below;

Try something like this (works as a Beanshell script and augments each
border by 10 pixels):

import ij.IJ;
import ij.ImagePlus;

// change these variables as needed
int extraBorder = 10;

ImagePlus imp = IJ.getImage();
Rectangle oldRoi = imp.getRoi().getBounds();
int newHeight = oldRoi.height + 2*extraBorder;
int newWidth = oldRoi.width + 2*extraBorder;
int newOffsetY = oldRoi.y - extraBorder;
int newOffsetX = oldRoi.x - extraBorder;
imp.setRoi(newOffsetX, newOffsetY, newWidth, newHeight);       
IJ.run("Duplicate...", "title");


Jon



--
Sent from: http://micro-manager.3463995.n2.nabble.com/


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general


--
RNDr. Radek Macháň, Ph.D.

Faculty of Science, Charles University in Prague
Imaging methods core facility
BIOCEV
Průmyslová 595, Vestec u Prahy
252 50, Czech Republic

Mob: +420 734 367 901
Tel: +420 325 873 940
Office: L1.013



_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

ImSplitCrop1.txt (544 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Java ImagePlus duplicate(). I do not want to duplicate ROI, but want to duplicate coordinates specified by me

SaralaT

Hi Jon, Radek and Nick,


Thanks a lot for your response! I seem to have managed doing the duplication of ROI using Jon's suggested method;


Rectangle oldRoi = imp.getRoi().getBounds();
int extraBorder = 300;
int newHeight = oldRoi.height + 2*extraBorder;
int newWidth = oldRoi.width + 2*extraBorder;
int newOffsetY = oldRoi.y - extraBorder;
int newOffsetX = oldRoi.x - extraBorder;
imp.setRoi(newOffsetX, newOffsetY, newWidth, newHeight);  
imp3 = new Duplicator().run(imp, 1, 1);

seems to work okay 😊


Thanks a gain


Best Regards,

Sarala


From: Radek Macháň <[hidden email]>
Sent: Saturday, November 3, 2018 5:16:54 AM
To: [hidden email]
Subject: Re: [micro-manager-general] Java ImagePlus duplicate(). I do not want to duplicate ROI, but want to duplicate coordinates specified by me
 
Hi Sarala,

See the attached macro which takes an ROI from the image duplicates it and then makes another ROI shifted by a specified number of pixels and duplicates that one as well. Would something analogous to this work for you?

Best wishes,
Radek

On Fri, 2 Nov 2018 at 17:12, JonD <[hidden email]> wrote:
SaralaT wrote
> I am writing an Micromanager plugin, and right now it is able to take
> images by camera, and the user places an ROI on the image. Then I would
> like to save an area slightly larger than the ROI (x,y,width and height
> given be me). But I am currently trying to use  the below;

Try something like this (works as a Beanshell script and augments each
border by 10 pixels):

import ij.IJ;
import ij.ImagePlus;

// change these variables as needed
int extraBorder = 10;

ImagePlus imp = IJ.getImage();
Rectangle oldRoi = imp.getRoi().getBounds();
int newHeight = oldRoi.height + 2*extraBorder;
int newWidth = oldRoi.width + 2*extraBorder;
int newOffsetY = oldRoi.y - extraBorder;
int newOffsetX = oldRoi.x - extraBorder;
imp.setRoi(newOffsetX, newOffsetY, newWidth, newHeight);       
IJ.run("Duplicate...", "title");


Jon



--
Sent from: http://micro-manager.3463995.n2.nabble.com/


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general


--
RNDr. Radek Macháň, Ph.D.

Faculty of Science, Charles University in Prague
Imaging methods core facility
BIOCEV
Průmyslová 595, Vestec u Prahy
252 50, Czech Republic

Mob: +420 734 367 901
Tel: +420 325 873 940
Office: L1.013



_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general