Newbie question

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

Newbie question

bateman
This post was updated on .
I'm trying to invert a line of pixels in my image, why does the following code compile but not do anything?

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.*;

public class First_Profile implements PlugInFilter {
        ImagePlus imp;

        public int setup(String arg, ImagePlus imp) {
                this.imp = imp;
                return DOES_ALL;
        }

        public void run(ImageProcessor ip) {
                               
                int width = ip.getWidth();
                int height = ip.getHeight();
                int profile[ ] = new int[width];

                for(int i = 0; i<width; i++){
                        int p = ip.getPixel((height/4), i);
                        ip.putPixel(width, height, 255- p);
                                                               
                }
}
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question

dscho
Hi bateman,

On Wed, 4 Apr 2012, bateman wrote:

> I'm trying to invert a line of pixels in my image, why does the following
> code compile but not do anything?
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.filter.*;
>
> public class First_Profile implements PlugInFilter {
> ImagePlus imp;
>
> public int setup(String arg, ImagePlus imp) {
> this.imp = imp;
> return DOES_ALL;
> }
>
> public void run(ImageProcessor ip) {
>
> int width = ip.getWidth();
> int height = ip.getHeight();
> int profile[ ] = new int[width];
>
> for(int i = 0; i<width; i++){
> int p = ip.getPixel((height/4), i);
> ip.putPixel(width, height, 255- p);
>
> }

You probably need to ask ImageJ to display the result:

                imp.updateAndDraw();

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question

Michael Schmid
In reply to this post by bateman
Hi Bateman,

pixel coordinates run from 0 to width-1 and 0 to height-1.
So ip.putPixel(width, height, ...) addresses a pixel outside of the image, and that's the only pixel that you change.

BTW, in a PlugInFilter you need not care about things like updateAndDraw.

Michael
________________________________________________________________
On Apr 4, 2012, at 16:26, bateman wrote:

> I'm trying to invert a line of pixels in my image, why does the following
> code compile but not do anything?
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.filter.*;
>
> public class First_Profile implements PlugInFilter {
> ImagePlus imp;
>
> public int setup(String arg, ImagePlus imp) {
> this.imp = imp;
> return DOES_ALL;
> }
>
> public void run(ImageProcessor ip) {
>
> int width = ip.getWidth();
> int height = ip.getHeight();
> int profile[ ] = new int[width];
>
> for(int i = 0; i<width; i++){
> int p = ip.getPixel((height/4), i);
> ip.putPixel(width, height, 255- p);
>
> }
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question

Benjamin Grant
Batemen,
aren't you trying to invert the same pixel that you selected?

>                       int p = ip.getPixel((height/4), i);
>                       ip.putPixel(width, height, 255- p);

so your indexing should be the same for your second line that
ip.putPixel(height/4, i, 255-p)


On Wed, Apr 4, 2012 at 10:59 AM, Michael Schmid <[hidden email]>wrote:

> Hi Bateman,
>
> pixel coordinates run from 0 to width-1 and 0 to height-1.
> So ip.putPixel(width, height, ...) addresses a pixel outside of the image,
> and that's the only pixel that you change.
>
> BTW, in a PlugInFilter you need not care about things like updateAndDraw.
>
> Michael
> ________________________________________________________________
> On Apr 4, 2012, at 16:26, bateman wrote:
>
> > I'm trying to invert a line of pixels in my image, why does the following
> > code compile but not do anything?
> >
> > import ij.*;
> > import ij.process.*;
> > import ij.gui.*;
> > import java.awt.*;
> > import ij.plugin.filter.*;
> >
> > public class First_Profile implements PlugInFilter {
> >       ImagePlus imp;
> >
> >       public int setup(String arg, ImagePlus imp) {
> >               this.imp = imp;
> >               return DOES_ALL;
> >       }
> >
> >       public void run(ImageProcessor ip) {
> >
> >               int width = ip.getWidth();
> >               int height = ip.getHeight();
> >               int profile[ ] = new int[width];
> >
> >               for(int i = 0; i<width; i++){
> >                       int p = ip.getPixel((height/4), i);
> >                       ip.putPixel(width, height, 255- p);
> >
> >               }
>
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question

bateman
Thanks everyone for the advice, I've got it working now.

Bateman