Login  Register

Padding in ImageJ

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Padding in ImageJ

bateman
Hi,

I wish to pad an image with zeros so that I may perform calculations on an image i.e. distances to other pixels etc.

I've seen the API has IJ.pad() function but I don't think this would work.

Does anyone have any ideas of an easy way/ suggestions on how to do this?

Thanks for your time
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Padding in ImageJ

Frederic V. Hessman
If you simply want to add/subtract rows/columns on the edges of your image, you can try my Image_Padder plugin: http://www.astro.physik.uni-goettingen.de/~hessman/ImageJ/

Rick


On 1 Nov 2012, at 10:48, bateman wrote:

> Hi,
>
> I wish to pad an image with zeros so that I may perform calculations on an
> image i.e. distances to other pixels etc.
>
> I've seen the API has IJ.pad() function but I don't think this would work.
>
> Does anyone have any ideas of an easy way/ suggestions on how to do this?
>
> Thanks for your time
>
>
>
> --
> View this message in context: http://imagej.1557.n6.nabble.com/Padding-in-ImageJ-tp5000622.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
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Padding in ImageJ

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by bateman
On Nov 1, 2012, at 5:48 AM, bateman wrote:

> Hi,
>
> I wish to pad an image with zeros so that I may perform calculations on an
> image i.e. distances to other pixels etc.
>
> I've seen the API has IJ.pad() function but I don't think this would work.
>
> Does anyone have any ideas of an easy way/ suggestions on how to do this?

You can pad an image with zeros using the Image>Adjust>Canvas Size command.

Here is an example macro that creates a 512x512 image and pads it on all sides by 10 pixels:

  newImage("Untitled", "8-bit white", 512, 512, 1);
  run("Canvas Size...", "width=532 height=532 position=Center zero");

Here is a version of the macro that uses variables for the image size and the padding:

  size = 512;
  pad = 10;
  newImage("Untitled", "8-bit white", size, size, 1);
  size2 = size + pad*2;
  run("Canvas Size...", "width=&size2 height=&size2 position=Center zero");

Here is a JavaScript version that opens a 512x512 image and pads by 10:

  imp = IJ.createImage("Untitled", "8-bit white", 512, 512, 1);
  IJ.run(imp, "Canvas Size...", "width=532 height=532 position=Center zero");
  imp.show();

And here is a version of the script that uses variables:

  size = 512;
  pad = 10;
  imp = IJ.createImage("Untitled", "8-bit white", size, size, 1);
  size2 = size + pad*2;
  IJ.run(imp, "Canvas Size...", "width="+size2+" height="+size2+" position=Center zero");
  imp.show();

-wayne

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