Posted by
Tiago Ferreira-2 on
Aug 04, 2009; 2:10pm
URL: http://imagej.273.s1.nabble.com/AltGr-key-tp3691584p3691587.html
matthews <matthews@...> writes:
>
> Dear ImageJ users,
>
> I want to obtain the coordinates of all the pixels of an object.
> When I use getselectioncoordinates I obtain only the pixel coordinates of the
object edge.
> Do you have an easy solution
>
> Thank you for your help
>
> Cédric Matthews
> CNRS - IBDML - UMR 6216
> coresponsable technique
> Service Imagerie - Case 907
> Route de luminy
> 13288 Marseille cedex 9
> tél: 04.91.26.92.21 / fax: 04.91.82.06.82
>
> matthews@...
> pacaimagerie@...
>
http://rtmfm.ibl.fr/>
http://www.gdr2588.cnrs.fr/>
Dear Cédric
This macro would do that.
---------------------------------------------------
// List All Pixels Inside a ROI
//
// Select 'Image>Adjust>Threshold' before running this macro to list only
// thresholded pixels. For large ROIs it may be rather slow.
// Works with stacks and RGB images;
//
// Tiago Ferreira - 2009.01
//
// Credits:
http://rsb.info.nih.gov/ij/macros/js/ListPixelsInROI.js//
http://rsb.info.nih.gov/ij/macros/tools/ColorPickerTool.txt if(selectionType==-1 || selectionType>4 && selectionType!=9)
exit("Area selection required");
w=getWidth; h=getHeight; nC=getSliceNumber; nF=nSlices; b=bitDepth;
getThreshold(minInt, maxInt);
if(minInt==-1 || maxInt==-1) {minInt=0; maxInt=255;}
if(nF>1 && b!=24 ) {
Dialog.create("List ROI Pixels");
Dialog.addNumber("Start at Slice",nC);
Dialog.addNumber("End at Slice", nF);
Dialog.addMessage(" ");
Dialog.addNumber("Min Intensity", minInt);
Dialog.addNumber("Max Intensity", maxInt);
Dialog.show;
nC=Dialog.getNumber; nF=Dialog.getNumber;
minInt=Dialog.getNumber; maxInt=Dialog.getNumber;
if(nC<1 || nC>nF || nF>nSlices || nF<nC)
exit("Invalid Parameters...");
} else if(nF>1 && b==24 ) {
Dialog.create("List ROI Pixels");
Dialog.addNumber("Start at Slice",nC);
Dialog.addNumber("End at Slice", nF);
Dialog.show;
nC=Dialog.getNumber; nF=Dialog.getNumber;
if(nC<1 || nC>nF || nF>nSlices || nF<nC)
exit("Invalid Parameters...");
} else if(nF==1 && b!=24 ) {
Dialog.create("List ROI Pixels");
Dialog.addNumber("Min Intensity", minInt);
Dialog.addNumber("Max Intensity", maxInt);
Dialog.show;
minInt=Dialog.getNumber; maxInt=Dialog.getNumber;
}
setBatchMode(true);
count=1; start = getTime;
f=prepareTable("ROI Pixels List", "#\tX\tY\tZ\tIntensity");
getSelectionBounds(xTL, yTL, selWidth, selHeight);
if(selWidth==w) selWidth=selWidth-1;
if(selHeight==h) selHeight= selHeight-1;
run("Create Mask"); //make mask img
m=newArray(w*h);
for(x=0;x<w;x++)
for(y=0;y<h;y++)
m[y*w+x]=getPixel(x,y);
close; //close mask img
for (i=nC; i<=nF; i++) {
call("java.lang.System.gc");
setSlice(i);
for(x=xTL;(x<=xTL+selWidth);x++) {
for(y=yTL;(y<=yTL+selHeight);y++) {
showStatus("Listing "+i+"/"+nF+"...");
showProgress(i-1,nF);
v= getPixel(x, y);
if (bitDepth==24) {
r= (v>>16)&0xff; // extract red byte (bits 23-17)
g= (v>>8)&0xff; // extract green byte (bits 15-8)
b= v&0xff; // extract blue byte (bits 7-0)
v1=""+r+","+g+","+b+"";
maxInt=-1; minInt=-16777216; //white; black
} else
v1=v;
if (m[y*w+x]!=0 && v>=minInt && v<=maxInt)
print (f, count++ +"\t"+x+"\t"+y+"\t"+i+"\t"+v1);
}
}
}
stop= getTime;
showStatus("Finished... ("+count-1+" out of "+(selWidth*selHeight)*(nF-
nC+1)+
" pixels listed in "+((stop-start)/1000)+" seconds)");
setBatchMode(false);
function prepareTable(title,csvHeadings) {
title2= "["+title+"]"; f= title2;
if(isOpen(title))
print(f, "\\Clear");
else
run("New... ", "name="+title2+" type=Table width=250 height=600");
print(f, "\\Headings:"+csvHeadings);
return f;
}