Hi group,
I need to do a check for whether or not a certain point/pixel coordinate is contained in the ROI. My code is of the form for all pixels, if pixels is in ROI, do stuff The ROI is a path resulting from freehand selection. I was not able to find such a function in the API documentation. Is there a function like the one I'm describing? Any suggestions on how to implement it? Cheers, PER |
> I need to do a check for whether or not a certain point/pixel coordinate is
> contained in the ROI. > My code is of the form > for all pixels, if pixels is in ROI, do stuff > The ROI is a path resulting from freehand selection. > > I was not able to find such a function in the API documentation. Is there a > function like the one I'm describing? Any suggestions on how to implement it? There is a method in Roi.java called "contains" which perhaps does what you need (not entirely sure). However if you have many pixels this may be slow. Alternatively you could create a binary image that has just the filled ROI, then use this image to direct the analysis (scan this image and all set pixels give you the coordinates of the pixels in the original that need to be processed). I hope it helps. Gabriel |
Yes, there is contains(), and it´s in the docs
http://rsb.info.nih.gov/ij/developer/api/ij/gui/Roi.html (look for contains) but it´s very general yet a bit slow, in case you need to access it in a tight loop you better create that mask Gabriel mentions once like byte rMask[] = null; Rectangle rRect = null; if (roi != null) { rRect = roi.getBounds(); ImageProcessor ipm = roi.getMask(); if (ipm != null) { rMask = (byte[])ipm.getPixels(); } } and later use your own contains() function. boolean contains(int ix, int iy, byte[] mask, Rectangle rect) { if (rect == null) return true; if (!rect.contains(ix, iy)) return false; if (mask == null) return true; return (mask[(iy-rect.y)*rect.width+(ix-rect.x)] != 0); } in a tight loop like if (contains(ix, iy, rMask, rRect)) { // do smothing if (ix,iy) is contained in the ROI } which is much faster! JW Gabriel Landini <G.Landini@BHAM. An: [hidden email] AC.UK> Kopie: Gesendet von: Thema: Re: how to access the ROI programmatically? ImageJ Interest Group <[hidden email] .GOV> 03.07.2006 22:20 Bitte antworten an ImageJ Interest Group > I need to do a check for whether or not a certain point/pixel coordinate is > contained in the ROI. > My code is of the form > for all pixels, if pixels is in ROI, do stuff > The ROI is a path resulting from freehand selection. > > I was not able to find such a function in the API documentation. Is there a > function like the one I'm describing? Any suggestions on how to implement it? There is a method in Roi.java called "contains" which perhaps does what you need (not entirely sure). However if you have many pixels this may be slow. Alternatively you could create a binary image that has just the filled ROI, then use this image to direct the analysis (scan this image and all set pixels give you the coordinates of the pixels in the original that need to be processed). I hope it helps. Gabriel ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
Dear All
Could I ask for some clarification on how the import dicom sequence works. Does it work on the principle that the *.dcm files are all in the order that they are listed in the directory. The reason I ask is because that I notice in unix when using ls it lists the *dcm files that start with a 1 first and then list the others therefore IM-1000.dcm comes before IM-900.dcm. Is this the order they will stack ? How can I check ? Anna Anna Barnes, PhD fMRI Research Laboratory Department of Radiology Columbia University College of Physicians and Surgeons 710 W168th St New York, NY10032 USA +1212 342 0293 |
I worked out how to check so now how do I fix it to read the file
names in numerical order ? Anna On Jul 3, 2006, at 5:59 PM, Anna Barnes wrote: > Dear All > Could I ask for some clarification on how the import dicom sequence > works. Does it work on the principle that the *.dcm files are all > in the order that they are listed in the directory. The reason I > ask is because that I notice in unix when using ls it lists the > *dcm files that start with a 1 first and then list the others > therefore IM-1000.dcm comes before IM-900.dcm. Is this the order > they will stack ? How can I check ? > > Anna > > > Anna Barnes, PhD > fMRI Research Laboratory > Department of Radiology > Columbia University College of Physicians and Surgeons > 710 W168th St > New York, NY10032 > USA > +1212 342 0293 |
In reply to this post by Anna Barnes
> Could I ask for some clarification on how the import dicom sequence
> works. Does it work on the principle that the *.dcm files are all > in the order that they are listed in the directory. The reason I > ask is because that I notice in unix when using ls it lists the > *dcm files that start with a 1 first and then list the others > therefore IM-1000.dcm comes before IM-900.dcm. Is this the order > they will stack ? How can I check ? The File>Import>Image Sequence command opens DICOM files in image number (0020,0013) order when all the images are in the same series, otherwise it opens them in alphanumeric file name order. -wayne |
Hi
Thanks for explaining. So I tried to fix it by creating 2 substacks and then adding them back together in the right order but I'm not sure how to do it. Is there away of adding the two new stack together so that the images are reordered ? Thanks Anna On Jul 3, 2006, at 6:19 PM, Rasband Wayne wrote: >> Could I ask for some clarification on how the import dicom >> sequence works. Does it work on the principle that the *.dcm >> files are all in the order that they are listed in the directory. >> The reason I ask is because that I notice in unix when using ls it >> lists the *dcm files that start with a 1 first and then list the >> others therefore IM-1000.dcm comes before IM-900.dcm. Is this the >> order they will stack ? How can I check ? > > The File>Import>Image Sequence command opens DICOM files in image > number (0020,0013) order when all the images are in the same > series, otherwise it opens them in alphanumeric file name order. > > -wayne |
In reply to this post by Per Christian Henden
Hi Per,
Maybe check that roi isn't null, then something like this: Roi roi =imp.getRoi(); Rectangle rect = roi.getBounds(); rx = rect.x; ry = rect.y; w = rect.width; h = rect.height; for(int y=ry; y<ry+h; y++) for(int x=rx; x<rx+w; x++) { if(roi.contains(x, y)) { ......do what you want to do } -------------- Original message ---------------------- From: Per Christian Henden <[hidden email]> > Hi group, > > I need to do a check for whether or not a certain point/pixel coordinate is > contained in the ROI. > My code is of the form > for all pixels, if pixels is in ROI, do stuff > The ROI is a path resulting from freehand selection. > > I was not able to find such a function in the API documentation. Is there a > function like the one I'm describing? Any suggestions on how to implement it? > > Cheers, > > PER |
In reply to this post by Anna Barnes
Wayne, Something is wrong with the import sequence. I copied and renamed
first two dicom files (09752176 and 09752197) in a directory so that there will be an additional two files (09769678 and 09769679) after the last file (09769677) in the same directory. When I use Import>Image Sequence, the two additional files (09769678 and 09769679) appear just after the first (09752176) and third image (09752197) in the sequence. Is there any particular reason this thing is happening? Ahmed -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Anna Barnes Sent: Monday, 03 July, 2006 7:39 PM To: [hidden email] Subject: Re: import dicom sequence plugin Hi Thanks for explaining. So I tried to fix it by creating 2 substacks and then adding them back together in the right order but I'm not sure how to do it. Is there away of adding the two new stack together so that the images are reordered ? Thanks Anna On Jul 3, 2006, at 6:19 PM, Rasband Wayne wrote: >> Could I ask for some clarification on how the import dicom sequence >> works. Does it work on the principle that the *.dcm >> files are all in the order that they are listed in the directory. >> The reason I ask is because that I notice in unix when using ls it >> lists the *dcm files that start with a 1 first and then list the >> others therefore IM-1000.dcm comes before IM-900.dcm. Is this the >> order they will stack ? How can I check ? > > The File>Import>Image Sequence command opens DICOM files in image > number (0020,0013) order when all the images are in the same series, > otherwise it opens them in alphanumeric file name order. > > -wayne |
In reply to this post by Joachim Wesner
Thanks!
Using contains() to build the mask and then just reading the mask to decide if I want to include the current pixel or not in the computation sounds like a good idea. To speed things up further I will ignore pixels outside the bounding rectangle of the ROI completely, i.e. make the for all pixels loop consider only the bounding rectangle. Cheers, PER On Monday 03 July 2006 22:56, Joachim Wesner wrote: > Yes, there is contains(), and it´s in the docs > > http://rsb.info.nih.gov/ij/developer/api/ij/gui/Roi.html (look for > contains) > > but it´s very general yet a bit slow, in case you need to access it in a > tight loop you better create that mask Gabriel mentions once like > > byte rMask[] = null; > Rectangle rRect = null; > if (roi != null) { > rRect = roi.getBounds(); > ImageProcessor ipm = roi.getMask(); > if (ipm != null) { > rMask = (byte[])ipm.getPixels(); > } > } > > and later use your own contains() function. > > boolean contains(int ix, int iy, byte[] mask, Rectangle rect) { > > if (rect == null) > return true; > > if (!rect.contains(ix, iy)) > return false; > > if (mask == null) > return true; > > return (mask[(iy-rect.y)*rect.width+(ix-rect.x)] != 0); > } > > in a tight loop like > > if (contains(ix, iy, rMask, rRect)) > { > // do smothing if (ix,iy) is contained in the ROI > } > > which is much faster! > > > JW > > > > > Gabriel Landini > <G.Landini@BHAM. An: [hidden email] > AC.UK> Kopie: > Gesendet von: Thema: Re: how to access > the ROI programmatically? ImageJ Interest > Group > <[hidden email] > .GOV> > > > 03.07.2006 22:20 > Bitte antworten > an ImageJ > Interest Group > > > I need to do a check for whether or not a certain point/pixel coordinate > > is > > > contained in the ROI. > > My code is of the form > > for all pixels, if pixels is in ROI, do stuff > > The ROI is a path resulting from freehand selection. > > > > I was not able to find such a function in the API documentation. Is there > > a > > > function like the one I'm describing? Any suggestions on how to implement > > it? > > There is a method in Roi.java called "contains" which perhaps does what you > > need (not entirely sure). > However if you have many pixels this may be slow. > > Alternatively you could create a binary image that has just the filled ROI, > > then use this image to direct the analysis (scan this image and all set > pixels give you the coordinates of the pixels in the original that need to > be > processed). > > I hope it helps. > > Gabriel > > > > ______________________________________________________________________ > This email has been scanned by the MessageLabs Email Security System. > For more information please visit http://www.messagelabs.com/email > ______________________________________________________________________ |
Free forum by Nabble | Edit this page |