Hello!
I am using Mac OS9 and I want to know how to get the number of pixels in an RGB image with a predefined color [like (255,255,255)] and copy this number in the clipboard? Thank you very much! Guenter Bachelier |
> I am using Mac OS9 and I want to know how to get the
> number of pixels in an RGB image with a predefined color > [like (255,255,255)] and copy this number in the clipboard? You can count the number of pixels with a predefined color using a macro like the one below but there is currently no easy way to programmatically copy text to the clipboard. -wayne red = 255; green = 255; blue = 255; if (bitDepth!=24) exit("RGB Image required"); count = getCount(red, green, blue); print("Count for "+red+","+green+","+blue+" = "+ count); print("Area fraction = "+count*100/(getWidth*getHeight) + "%"); exit; function getCount(red, green, blue) { color = red<<16 + green<<8 + blue; w= getHeight; h = getHeight; count = 0; for (y=0; y<getHeight; y++) { for (x=0; x<getWidth; x++) { if (getPixel(x, y)&0xffffff==color) count++; } if (y%10==0) showProgress(y, h); } return count; } |
Hello Wayne!
Thank you, your macro works fine. But if I want to integrate it in the lager workflow of the script program OneClick (see background info below) there is a problem. OneClick can automate the installation of the macro ( I named it "Count255") after each new opening of ImageJ (with >Type Command Shift "m"<) but running the macro does not work. It should work with >SelectMenu "Plugins", "Macros", "Count255"< but OneClick have difficulties to cope with ImageJ menus and buttons. The content in the log window after the run of the macro "Count255" (activated by hand) can be copied into the clipboard (with >Type Command "ac"<), and from there in BBEdit where I can automatically extract the integer. But if I can not activate the macro with OneClick the whole strategy does not work. Is there any way to start such a macro with a keyboard command? I looked in the Keyboard Shortcut list, but there is no predefined shortcut for "run". I defined such a shortcut, it is shown under Plugins>Shortcuts>*Run..., and it worked when I select it from the menu, but after typing the shortcut nothing happens!? Background: I want to select those images from a large set of tiffs which have more than a predefined number of pixels of a specific color. If they have more, they are "non valid", and they should be moved to the Trash, otherwise they will be moved to an other folder. I had planed to use ImageJ to determine the number of pixels, copy the integer in the clipboard, use the clipboard content as the value of a variable in OneClick and use the FinderMove command in OneClick to do the moving. Until now I have used the histogram (with >Type Command "h"<) as a workaround, but the buttons in the histogram interface can not be pushed by a keyboard command, so I had to use the often problematic Click x,y command to push the "Copy" button by which the whole histogram list is copied in the clipboard. thank you very much. Guenter Bachelier Wayne Rasband wrote: > > I am using Mac OS9 and I want to know how to get the > > number of pixels in an RGB image with a predefined color > > [like (255,255,255)] and copy this number in the clipboard? > > You can count the number of pixels with a predefined color using a > macro like the one below but there is currently no easy way to > programmatically copy text to the clipboard. > > -wayne > > red = 255; > green = 255; > blue = 255; > if (bitDepth!=24) > exit("RGB Image required"); > count = getCount(red, green, blue); > print("Count for "+red+","+green+","+blue+" = "+ count); > print("Area fraction = "+count*100/(getWidth*getHeight) + "%"); > exit; > > function getCount(red, green, blue) { > color = red<<16 + green<<8 + blue; > w= getHeight; > h = getHeight; > count = 0; > for (y=0; y<getHeight; y++) { > for (x=0; x<getWidth; x++) { > if (getPixel(x, y)&0xffffff==color) > count++; > } > if (y%10==0) showProgress(y, h); > } > return count; > } |
Free forum by Nabble | Edit this page |