Where am I wrong ?

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

Where am I wrong ?

Andrew-98
> Dear
> I have a 8 bit grey scale jpeg image i want to read it and save it again
> in jpg format.Please  check the code and please tell me where am I wrong.
>           FileInfo fi = new  FileInfo();
>           fi.fileFormat=3 ;
>           fi.fileType =0;
>           fi.nImages=1;
>           fi.width = 256;
>           fi.height = 256;
>
>           ImageReader imreader = new ImageReader(fi);
>           byte [] pixel = (byte[])imreader.    readPixels(new
> FileInputStream(" 1.jpg"));
>
>           ImageProcessor imp = new ByteProcessor(256,256,pixel,null);
>           ImagePlus img = new ImagePlus("", imp);
>           (new FileSaver(img)).saveAsJpeg("test.jpg");
>

    Thanks .
Reply | Threaded
Open this post in threaded view
|

Re: Where am I wrong ?

Wayne Rasband
Here is a two line macro, generated with the command recorder, that
opens a 256x256 8-bit image and re-saves in JPEG format:

   run("Raw...", "open=[/Users/wayne/test.raw] image=8-bit width=256
height=256 offset=0 number=1 gap=0");
   saveAs("Jpeg", "/Users/wayne/test.jpg");

As a plugin, it looks like this:

   IJ.run("Raw...", "open=[/Users/wayne/test.raw] image=8-bit width=256
height=256 offset=0 number=1 gap=0");
   IJ.saveAs("Jpeg", "/Users/wayne/test.jpg");

-wayne


On Aug 29, 2006, at 3:22 PM, Andrew wrote:

>> Dear
>> I have a 8 bit grey scale jpeg image i want to read it and save it
>> again
>> in jpg format.Please  check the code and please tell me where am I
>> wrong.
>>           FileInfo fi = new  FileInfo();
>>           fi.fileFormat=3 ;
>>           fi.fileType =0;
>>           fi.nImages=1;
>>           fi.width = 256;
>>           fi.height = 256;
>>
>>           ImageReader imreader = new ImageReader(fi);
>>           byte [] pixel = (byte[])imreader.    readPixels(new
>> FileInputStream(" 1.jpg"));
>>
>>           ImageProcessor imp = new ByteProcessor(256,256,pixel,null);
>>           ImagePlus img = new ImagePlus("", imp);
>>           (new FileSaver(img)).saveAsJpeg("test.jpg");
>>
>
>    Thanks .
>
Reply | Threaded
Open this post in threaded view
|

Re: Where am I wrong ?

Sanjay Verma
Thanks for quick reply , but this code also giving the wrong result(as
previous).
Please check my code again and tell me where am I wrong.I want to know where
am i wrong.
bye

On 8/30/06, Wayne Rasband <[hidden email]> wrote:

>
> Here is a two line macro, generated with the command recorder, that
> opens a 256x256 8-bit image and re-saves in JPEG format:
>
>    run("Raw...", "open=[/Users/wayne/test.raw] image=8-bit width=256
> height=256 offset=0 number=1 gap=0");
>    saveAs("Jpeg", "/Users/wayne/test.jpg");
>
> As a plugin, it looks like this:
>
>    IJ.run("Raw...", "open=[/Users/wayne/test.raw] image=8-bit width=256
> height=256 offset=0 number=1 gap=0");
>    IJ.saveAs("Jpeg", "/Users/wayne/test.jpg");
>
> -wayne
>
>
> On Aug 29, 2006, at 3:22 PM, Andrew wrote:
>
> >> Dear
> >> I have a 8 bit grey scale jpeg image i want to read it and save it
> >> again
> >> in jpg format.Please  check the code and please tell me where am I
> >> wrong.
> >>           FileInfo fi = new  FileInfo();
> >>           fi.fileFormat=3 ;
> >>           fi.fileType =0;
> >>           fi.nImages=1;
> >>           fi.width = 256;
> >>           fi.height = 256;
> >>
> >>           ImageReader imreader = new ImageReader(fi);
> >>           byte [] pixel = (byte[])imreader.    readPixels(new
> >> FileInputStream(" 1.jpg"));
> >>
> >>           ImageProcessor imp = new ByteProcessor(256,256,pixel,null);
> >>           ImagePlus img = new ImagePlus("", imp);
> >>           (new FileSaver(img)).saveAsJpeg("test.jpg");
> >>
> >
> >    Thanks .
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Where am I wrong ?

Ankur Purwar
Sanjay,

your code can read only raw image files!

So, for reading Jpeg/BMP etc use class Opener from the package ij.io. and
for writing in JPEG/BMP etc use FileSaver again from the same package.

-Ankur



> Thanks for quick reply , but this code also giving the wrong result(as
> previous).
> Please check my code again and tell me where am I wrong.I want to know
> where
> am i wrong.
> bye
>
> On 8/30/06, Wayne Rasband <[hidden email]> wrote:
>>
>> Here is a two line macro, generated with the command recorder, that
>> opens a 256x256 8-bit image and re-saves in JPEG format:
>>
>>    run("Raw...", "open=[/Users/wayne/test.raw] image=8-bit width=256
>> height=256 offset=0 number=1 gap=0");
>>    saveAs("Jpeg", "/Users/wayne/test.jpg");
>>
>> As a plugin, it looks like this:
>>
>>    IJ.run("Raw...", "open=[/Users/wayne/test.raw] image=8-bit width=256
>> height=256 offset=0 number=1 gap=0");
>>    IJ.saveAs("Jpeg", "/Users/wayne/test.jpg");
>>
>> -wayne
>>
>>
>> On Aug 29, 2006, at 3:22 PM, Andrew wrote:
>>
>> >> Dear
>> >> I have a 8 bit grey scale jpeg image i want to read it and save it
>> >> again
>> >> in jpg format.Please  check the code and please tell me where am I
>> >> wrong.
>> >>           FileInfo fi = new  FileInfo();
>> >>           fi.fileFormat=3 ;
>> >>           fi.fileType =0;
>> >>           fi.nImages=1;
>> >>           fi.width = 256;
>> >>           fi.height = 256;
>> >>
>> >>           ImageReader imreader = new ImageReader(fi);
>> >>           byte [] pixel = (byte[])imreader.    readPixels(new
>> >> FileInputStream(" 1.jpg"));
>> >>
>> >>           ImageProcessor imp = new ByteProcessor(256,256,pixel,null);
>> >>           ImagePlus img = new ImagePlus("", imp);
>> >>           (new FileSaver(img)).saveAsJpeg("test.jpg");
>> >>
>> >
>> >    Thanks .
>> >
>>
>