> you don't need a plug in for that, as you'll soon find out when you start
> learning how to write your own.
>
> to do that with the current plugin all you need to do is but add three
> lines
> of code:
>
> 1) describe the red only pixel you'd like to replace the partially red
> pixels with:
> "private final static int[] REDPIXEL = {255, 0, 0};"
> 2) as well as counting the non-grey scale pixels also replace them with
> your
> red only pixel:
> "colours.putPixel(i, j, REDPIXEL);"
> 3) redraw the image:
> "imp.draw();"
>
> which gives:
>
> import ij.plugin.PlugIn;
> import ij.ImagePlus;
> import ij.IJ;
> import ij.WindowManager;
> import ij.process.*;
> import ij.measure.*;
>
> public final class RedAreaCalculator_ implements PlugIn {
> private ImagePlus imp;
> private final static String COLUMN_HEADING = "percentage red";
> private final static int[] REDPIXEL = {255, 0, 0};
>
> public void run(String arg) {
> imp = WindowManager.getCurrentImage();
> int bitDepth = imp.getBitDepth();
> if (bitDepth ==24) {
> CalculatePercentageRed();
> } else {
> IJ.error("RGB image required");
> }
>
> }
>
> private void CalculatePercentageRed(){
>
> ImageProcessor colours = imp.getProcessor();
> int[] RGB = new int[3];
> int ImageWidth = colours.getWidth();
> int ImageHeight = colours.getHeight();
> final int totalPixelNumber = ImageWidth*ImageHeight;
>
> int sumOfRedPixels = 0;
> for (int i = 0 ; i < ImageWidth ; ++i) {
> for (int j = 0 ; j < ImageHeight ; ++j) {
> RGB = colours.getPixel(i, j, RGB);
> if (RGB[0] != RGB[1]) {
> sumOfRedPixels = sumOfRedPixels +1;
> colours.putPixel(i, j, REDPIXEL);
> }
> }
> }
> imp.draw();
> double percentage =
> (sumOfRedPixels*100.00)/totalPixelNumber;
> ResultsTable rt = ResultsTable.getResultsTable();
> int column = rt.getColumnIndex(COLUMN_HEADING);
> if (column == -1) {
> rt.addColumns();
> column = rt.getFreeColumn(COLUMN_HEADING);
> }
> rt.incrementCounter();
> rt.addValue(column, percentage);
> rt.show("Results");
> }
> }
>
> which when compiled gives
>
http://dl.dropbox.com/u/2014897/RedAreaCalculator_.class>
> you might like to start with some on-line tutorials in the basics:
>
>
http://java.sun.com/docs/books/tutorial/>
> I don't think they are as well written as the book though.
> --
> View this message in context:
>
http://n2.nabble.com/Driving-me-nuts-tp4770479p4783380.html> Sent from the ImageJ mailing list archive at Nabble.com.
>