How to save an image in different formats

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

How to save an image in different formats

sabau daniel
Hello,I'm new in imagej, and i want to make a field/label with an option to save an image in jpg,tiff,jpeg .How to do that,how to implement in the following code.Thanks.
import java.io.File;

import ij.IJ;

import ij.ImagePlus;

import ij.plugin.PlugIn;

importij.process.ImageProcessor;


 
//This plugin shows the basicstructure of a code.

public class Open_Image implements PlugIn {

       public void run(String arg) { //Method Belongingto PlugIn Implementation

             

              StringmyDirector1 = IJ.getDirectory("Select SourceFolder...");        //This pluginopens the select folder window in ImageJ

              if (myDirector1==null) return;                                                                              //If not sourcefolder is selected the plugin stops here

              String[]myListSources = new File(myDirector1).list();                                        //This string contains all the filesnames in the source folder

              if (myListSources==null) return;

              IJ.log("The sourceimage folder chosen was"+myDirector1);                              //This command opens the log window andwrites on the variables on it.

             

              StringmyDirector2 = IJ.getDirectory("Select SavingFolder...");

              if (myDirector2==null) return;                                                                              //If not savingfolder is selected the plugin stops here

              IJ.log("The savingfolder chosen was"+myDirector2);

                    

              int Image;


 
              for (Image = 0; Image < myListSources.length; Image++) {

                    

                     IJ.showProgress(Image,myListSources.length);                                    //This command sets magnitude the progressbar on ImageJ

                     IJ.log((Image+1)+":"+myListSources[Image]);

                     IJ.showStatus(Image+"/"+myListSources.length);                                         //This command sets a text in theImageJ status bar

                    

                           ImagePlusmyImPlus = IJ.openImage(myDirector1+myListSources[Image]);

                           myImPlus.show();                                                                               //This commandopens a window with the corresponding ImagePlus

                           ImageProcessormyIp = myImPlus.getProcessor();

                           myImPlus.updateAndDraw();


             

              IJ.log("Completed");

       }

}


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to save an image in different formats

Herbie
Good day Daniel,

is it necessary for you to use an ImageJ-PlugIn for your purpose?

If not, you may have a look the ImageJ-Macro language which is much easier:
<http://rsb.info.nih.gov/ij/developer/index.html>

"want to make a field/label with an option to save an image"

Could you please explain in more detail what you want and perhaps you
can supply access to a typical example image, so we can see where the
label is to be put.

Best

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 26.04.16 um 17:35 schrieb sabau daniel:

> Hello,I'm new in imagej, and i want to make a field/label with an
> option to save an image in jpg,tiff,jpeg .How to do that,how to
> implement in the following code.Thanks. import java.io.File;
>
> import ij.IJ;
>
> import ij.ImagePlus;
>
> import ij.plugin.PlugIn;
>
> importij.process.ImageProcessor;
>
>
>
> //This plugin shows the basicstructure of a code.
>
> public class Open_Image implements PlugIn {
>
> public void run(String arg) { //Method Belongingto PlugIn
> Implementation
>
>
>
> StringmyDirector1 = IJ.getDirectory("Select SourceFolder...");
> //This pluginopens the select folder window in ImageJ
>
> if (myDirector1==null) return;
> //If not sourcefolder is selected the plugin stops here
>
> String[]myListSources = new File(myDirector1).list();
> //This string contains all the filesnames in the source folder
>
> if (myListSources==null) return;
>
> IJ.log("The sourceimage folder chosen was"+myDirector1);
> //This command opens the log window andwrites on the variables on
> it.
>
>
>
> StringmyDirector2 = IJ.getDirectory("Select SavingFolder...");
>
> if (myDirector2==null) return;
> //If not savingfolder is selected the plugin stops here
>
> IJ.log("The savingfolder chosen was"+myDirector2);
>
>
>
> int Image;
>
>
>
> for (Image = 0; Image < myListSources.length; Image++) {
>
>
>
> IJ.showProgress(Image,myListSources.length);
> //This command sets magnitude the progressbar on ImageJ
>
> IJ.log((Image+1)+":"+myListSources[Image]);
>
> IJ.showStatus(Image+"/"+myListSources.length);
> //This command sets a text in theImageJ status bar
>
>
>
> ImagePlusmyImPlus = IJ.openImage(myDirector1+myListSources[Image]);
>
> myImPlus.show();
> //This commandopens a window with the corresponding ImagePlus
>
> ImageProcessormyIp = myImPlus.getProcessor();
>
> myImPlus.updateAndDraw();
>
>
>
>
> IJ.log("Completed");
>
> }
>
> }
>
>
> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to save an image in different formats

Herbie
In reply to this post by sabau daniel
Daniel,

is this (example) macro

//
newImage("Example", "8-bit random", 128, 128, 1);
format = getString("Please enter either 'tiff',  'jpeg', or 'png'
without quotation marks.", "tiff");
saveAs(format);
run("Close");
//

what you are looking for?
Open an empty macro text window (Plugins > New > Macro) and copy the
above to it and run...

Best

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 26.04.16 um 17:35 schrieb sabau daniel:

> Hello,I'm new in imagej, and i want to make a field/label with an
> option to save an image in jpg,tiff,jpeg .How to do that,how to
> implement in the following code.Thanks. import java.io.File;
>
> import ij.IJ;
>
> import ij.ImagePlus;
>
> import ij.plugin.PlugIn;
>
> importij.process.ImageProcessor;
>
>
>
> //This plugin shows the basicstructure of a code.
>
> public class Open_Image implements PlugIn {
>
> public void run(String arg) { //Method Belongingto PlugIn
> Implementation
>
>
>
> StringmyDirector1 = IJ.getDirectory("Select SourceFolder...");
> //This pluginopens the select folder window in ImageJ
>
> if (myDirector1==null) return;
> //If not sourcefolder is selected the plugin stops here
>
> String[]myListSources = new File(myDirector1).list();
> //This string contains all the filesnames in the source folder
>
> if (myListSources==null) return;
>
> IJ.log("The sourceimage folder chosen was"+myDirector1);
> //This command opens the log window andwrites on the variables on
> it.
>
>
>
> StringmyDirector2 = IJ.getDirectory("Select SavingFolder...");
>
> if (myDirector2==null) return;
> //If not savingfolder is selected the plugin stops here
>
> IJ.log("The savingfolder chosen was"+myDirector2);
>
>
>
> int Image;
>
>
>
> for (Image = 0; Image < myListSources.length; Image++) {
>
>
>
> IJ.showProgress(Image,myListSources.length);
> //This command sets magnitude the progressbar on ImageJ
>
> IJ.log((Image+1)+":"+myListSources[Image]);
>
> IJ.showStatus(Image+"/"+myListSources.length);
> //This command sets a text in theImageJ status bar
>
>
>
> ImagePlusmyImPlus = IJ.openImage(myDirector1+myListSources[Image]);
>
> myImPlus.show();
> //This commandopens a window with the corresponding ImagePlus
>
> ImageProcessormyIp = myImPlus.getProcessor();
>
> myImPlus.updateAndDraw();
>
>
>
>
> IJ.log("Completed");
>
> }
>
> }
>
>
> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to save an image in different formats

Herbie
In reply to this post by sabau daniel
OK Daniel,

my previous code snippet does what you want but without the drop-down menu.
Here is a polished version:

//
newImage( "Example", "8-bit random", 128, 128, 1 );
items = newArray( "TIFF","JPEG","PNG" );
Dialog.create( "Save Image" );
Dialog.addChoice( "Format:", items, items[0] );
Dialog.show();
format = Dialog.getChoice();
saveAs( format );
run( "Close" );
//

HTH

Herbie

:::::::::::::::::::::::::::::::::::::::::::::::::::::::
What i mean is like in this picture

figure images/SaveAsImageSequence.png


I want to have posibility to choose what format to save.


On Tuesday, April 26, 2016 7:59 PM, Herbie <[hidden email]> wrote:


Daniel,

is this (example) macro

//
newImage("Example", "8-bit random", 128, 128, 1);
format = getString("Please enter either 'tiff',  'jpeg', or 'png'
without quotation marks.", "tiff");
saveAs(format);
run("Close");
//

what you are looking for?
Open an empty macro text window (Plugins > New > Macro) and copy the
above to it and run...

Best

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 26.04.16 um 17:35 schrieb sabau daniel:
 > Hello,I'm new in imagej, and i want to make a field/label with an
 > option to save an image in jpg,tiff,jpeg .How to do that,how to
 > implement in the following code.Thanks. import java.io.File;
 >
 > import ij.IJ;
 >
 > import ij.ImagePlus;
 >
 > import ij.plugin.PlugIn;
 >
 > importij.process.ImageProcessor;
 >
 >
 >
 > //This plugin shows the basicstructure of a code.
 >
 > public class Open_Image implements PlugIn {
 >
 > public void run(String arg) { //Method Belongingto PlugIn
 > Implementation
 >
 >
 >
 > StringmyDirector1 = IJ.getDirectory("Select SourceFolder...");
 > //This pluginopens the select folder window in ImageJ
 >
 > if (myDirector1==null) return;
 > //If not sourcefolder is selected the plugin stops here
 >
 > String[]myListSources = new File(myDirector1).list();
 > //This string contains all the filesnames in the source folder
 >
 > if (myListSources==null) return;
 >
 > IJ.log("The sourceimage folder chosen was"+myDirector1);
 > //This command opens the log window andwrites on the variables on
 > it.
 >
 >
 >
 > StringmyDirector2 = IJ.getDirectory("Select SavingFolder...");
 >
 > if (myDirector2==null) return;
 > //If not savingfolder is selected the plugin stops here
 >
 > IJ.log("The savingfolder chosen was"+myDirector2);
 >
 >
 >
 > int Image;
 >
 >
 >
 > for (Image = 0; Image < myListSources.length; Image++) {
 >
 >
 >
 > IJ.showProgress(Image,myListSources.length);
 > //This command sets magnitude the progressbar on ImageJ
 >
 > IJ.log((Image+1)+":"+myListSources[Image]);
 >
 > IJ.showStatus(Image+"/"+myListSources.length);
 > //This command sets a text in theImageJ status bar
 >
 >
 >
 > ImagePlusmyImPlus = IJ.openImage(myDirector1+myListSources[Image]);
 >
 > myImPlus.show();
 > //This commandopens a window with the corresponding ImagePlus
 >
 > ImageProcessormyIp = myImPlus.getProcessor();
 >
 > myImPlus.updateAndDraw();
 >
 >
 >
 >
 > IJ.log("Completed");
 >
 > }
 >
 > }
 >
 >
 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html

 >

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Analyse intensity in image of diffraction pattern

Herbie
In reply to this post by sabau daniel
Apiot,

the greatest problem I see with analyzing intensities of the images is,
that they are over-exposed which results in unreliable intensity
measurements.

But there may be other problems if these images are from real
photographs. If so, you need to gamma-correct them for the non-linearity
of the photographic process. Gamma-correction requires knowledge about
the photographic material and the development process...

In case you are happy with an analysis of the position of the hexagonal
pattern, i.e. with a geometric analysis, both issues appear less important.

Please be more specific concerning the desired analyses.

Best

Herbie

:::::::::::::::::::::::::::::::::::
Am 28.04.16 um 14:32 schrieb Apiot:
 > <http://imagej.1557.x6.nabble.com/file/n5016265/dl%3D0%288bit%29.jpg>
 > <http://imagej.1557.x6.nabble.com/file/n5016265/dl%3D1mm%288bit%29.jpg>
 >
 > Hi,
 >
 > I'd like to use ImageJ to analyse the intensity of light in diffraction
 > pattern. I have to different photos of diffraction pattern. I assume,
that
 > the in intensity from each of the spots should differ for the photos.
 > Could You advice me, how to measure this values
 >
 > Thanks in advance
 >
 >
 >
 > --
 > View this message in context:
http://imagej.1557.x6.nabble.com/Analyse-intensity-in-image-of-diffraction-pattern-tp5016265.html
 > Sent from the ImageJ mailing list archive at Nabble.com.
 >
 > --
 > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
 >

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html