computers

posted by .

Need help with writing an imageJ plugin which is in java. Here is the question:
Create an ImageJ plugin for 8-bit grayscale images of arbitrary size that
paints a white frame (with pixel value 255) 10 pixels wide into the image.

Here is the current plugin to modify:

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

/** This sample ImageJ plug-in filter inverts 8-bit images.

A few things to note:
1) Filter plug-ins must implement the PlugInFilter interface.
2) Plug-ins located in the "plug-in" folder must not use
the package statement;
3) Plug-ins residing in the "plugins" folder and with at
least one underscore in their name will be automatically
installed in the PlugIns menu.
4) Plug-ins can be installed in other menus be editing
the ij.properties file.
5) You must edit ij.properties to get you plug-in to appear
in the Help->About PlugIns sub-menu.
6) The class name and file name must be the same.
7) This filter works with ROIs, including non-rectangular ROIs.
5) It will be called repeatedly to process all the slices in a stack.
6) This plug-in can't be named "Invert_" because this would
conflict with the built-in command of the same name.
7) The inverterting is accomplished with: pixels[i] = pixels[i] = (byte)(0);
8) Set ROI to value pixels[i] = (byte)(0);
*/

public class Inverter_ implements PlugInFilter {

public int setup(String arg, ImagePlus imp) {
if (arg.equals("about"))
{showAbout(); return DONE;}
return DOES_8G+DOES_STACKS+SUPPORTS_MASKING;
}

public void run(ImageProcessor ip) {
byte[] pixels = (byte[])ip.getPixels();
int width = ip.getWidth();
Rectangle r = ip.getRoi();
int offset, i;
for (int y=r.y; y<(r.y+r.height); y++) {
offset = y*width;
for (int x=r.x; x<(r.x+r.width); x++) {
i = offset + x;
pixels[i] = pixels[i] = (byte)(0);
}
}
}

void showAbout() {
IJ.showMessage("About Inverter_...",
"This sample plug-in filter inverts 8-bit images. Look\n" +
"at the 'Inverter_.java' source file to see how easy it is\n" +
"in ImageJ to process non-rectangular ROIs, to process\n" +
"all the slices in a stack, and to display an About box."
);
}
}

  • computers-java -

    Let's make this clear.

    The run method currently does the following:
    1. it gets ALL the pixels of a given image into pixel[].
    2. it gets the width of the full image and stores it into width.
    3. ip.getRoi() returns a rectangle r inside the image, starting at (r.x,r.y), and of dimensions r.width and r.height.
    4. it then paints the whole rectanlge in white (byte)(0) (invert?).

    So all you need to do is to modify the two for-statements so that it will paint white (invert?) only a frame of 10 pixels wide.

    This can be done in many ways, one of which is to put an if statement before the command:
    pixels[i] = pixels[i] = (byte)(0);
    so that only those pixels of the frame will be inverted, something like:

    if(..conditions..){
    pixels[i] = pixels[i] = (byte)(0);
    }

    So from the information above, try to work out the conditions required to invert the outermost 10 pixels of the rectangle r.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Java

    Write a GUI application that prompts the user for a number between 1 and 5. Be sure to include error checking so that the program continues to prompt the user for a number until the user's entry is between 1 and 5, inclusive. Once …
  2. Engineering

    ANPR system takes two images of each passing car. each image is 840 pixels wide and 320 pixels high. each pixel is stored in one byte. on average six car pass per minute. if each uncompressed image is sent back to the control centre …
  3. Engineering

    ANPR system takes two images of each passing car. each image is 840 pixels wide and 320 pixels high. each pixel is stored in one byte. on average six car pass per minute. if each uncompressed image is sent back to the control centre …
  4. engineering

    ANPR system takes two images of each passing car. each image is 840 pixels wide and 320 pixels high. each pixel is stored in one byte. on average six car pass per minute. if each uncompressed image is sent back to the control centre …
  5. statistics

    Is my answer correct. Q. How many megabytes of memory would be required to store an uncompressed 2-minute video file which is played at 24 frames per second, with a frame size of 320 × 240 pixels using a 24-bit per pixel colour model?
  6. Mathematics

    Images on a computer can be stored many ways to account for quality and space issues. One of the factors we can adjust is colour depth. Colour depth determines the number of bits we use for each pixel of an image. The pixels are the …
  7. reading

    46. Choosing the Resolution for Your Photos Resolution Purpose L (Large) Print larger than A4 size prints 2592 x 1944 pixels (8 .3 x 11 .7 in.) Print larger than letter size prints (8 .5 x 11 in.) M1 (Medium 1) Print up to A4 size …
  8. Reading

    41. Choosing the Resolution for Your Photos Resolution Purpose L (Large) 2592x1944 pixels Print larger that A 4 size prints (8.3 x 11.7 in.) Print larger than letter size prints (8.5 x 11 in.) M1 (Medium 1) 2048 x 1536 Print up to …
  9. Reading

    41. Choosing the Resolution for Your Photos Resolution Purpose L (Large) 2592x1944 pixels Print larger that A 4 size prints (8.3 x 11.7 in.) Print larger than letter size prints (8.5 x 11 in.) M1 (Medium 1) 2048 x 1536 Print up to …
  10. English

    41. Choosing the Resolution for Your Photos Resolution Purpose L (Large) 2592x1944 pixels Print larger that A 4 size prints (8.3 x 11.7 in.) Print larger than letter size prints (8.5 x 11 in.) M1 (Medium 1) 2048 x 1536 Print up to …

More Similar Questions