[BioC] Visualizing the region of classification uncertainty on thresholded images

Alex Gutteridge alexg at ruggedtextile.com
Tue Aug 7 10:28:00 CEST 2012


On 06.08.2012 16:26, Ravi [guest] wrote:
> Hi,
> I am now able to calculate the percent area of a certain phase on an
> image(thanks to the excellent help that I have received from this
> forum). My follow-up question is as follows :
> Depending on the threshold level chosen to create a binary image, the
> percent area calculated will vary. I would like to have a means of
> visualizing the uncertain regions represented by a threshold band
> level on the original image. If we start with the following code :
> library(CRImage)
> img = readImage(system.file("images", "nuclei.tif", 
> package="EBImage"))[,,1]
> display(img)
> t1=calculateOtsu(as.vector(img));t1c<-t1*255
> tdiff<-30
> t2c<-t1c+tdiff; t2=t2c/255 # A second threshold level
> timg<-table(img)
> names(timg)<-1:255
> plot(timg) # open to suggestions for better coding!

hist(img*255)

Gives you (almost) the same plot without the intermediate table step.

> abline(v=c(t1c,t2c),col="red")
>
> imgB=createBinaryImage(img,threshold=t1)
> imgB=!imgB #flip foreground to background
> imgS=bwlabel(imgB)
> fShape=computeFeatures.shape(imgS)
> percentArea=sum(fShape[,'s.area'])/length(img)*100
> percentArea
> # Attempt to visualise the area represented by a threshold band i,e, 
> (t2-t1)
> img2<-img
> crop1<-which(img2<t1)
> crop2<-which(img2>t2)
> crop<-c(crop1,crop2)
> img2[crop]<-1
> display(img2)
> # does not appear to be correct
> # the area seems to much greater than the 0.5%
> # obtained from the results of thresholding with t1 & t2

I'm not sure where you get 0.5% from? I get ~2.5%

> (length(which(img >= t1 & img <= t2))/length(img))*100
[1] 2.614379

Very hard for me to judge by eye, but the displayed image looks about 
right and I can't see an error in the code/logic.

> I don't think that img2 gives what I am hoping to get. As I mentioned
> previously, my intention is to identify the regions in img with
> intensity levels between t1 and t2 (the threshold band level
> represented by the red lines in the image histogram figure).
> I am interested in the following :
> 1. To color the uncertain regions in img2 with let’s say red colour
> and even have the choice of making it transparent. To then superpose
> img2 on top of the original image.
> 2. Maybe the reverse process is better. To make the original figure
> transparent and superpose it on img2.

Lots of different ways to do this, but does this get you started?

img3 = rgbImage((!img2)+img,img,img)
display(img3)

> I am perhaps asking for too much. But I would appreciate any tip that
> I can get.
> Thanks,
> Ravi Sutradhara
>
>
>  -- output of sessionInfo():
>
> R version 2.15.1 (2012-06-22)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252
> LC_MONETARY=Swedish_Sweden.1252
> [4] LC_NUMERIC=C                    LC_TIME=Swedish_Sweden.1252
>
> attached base packages:
> [1] splines   stats     graphics  grDevices utils     datasets
> methods   base
>
> other attached packages:
>  [1] CRImage_1.6.0      aCGH_1.34.0        multtest_2.12.0
> Biobase_2.16.0     BiocGenerics_0.2.0
>  [6] survival_2.36-14   cluster_1.14.2     DNAcopy_1.30.0
> EBImage_3.12.0     abind_1.4-0
>
> loaded via a namespace (and not attached):
> [1] class_7.3-4     codetools_0.2-8 e1071_1.6       foreach_1.4.0
> iterators_1.0.6 MASS_7.3-20     stats4_2.15.1
> [8] tools_2.15.1
>
> --
> Sent via the guest posting facility at bioconductor.org.
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
Alex Gutteridge



More information about the Bioconductor mailing list