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

Alex Gutteridge alexg at ruggedtextile.com
Tue Aug 7 15:51:15 CEST 2012


On 07.08.2012 13:53, ravi wrote:
> Hi Alex,
> Thanks a lot for your reply. You are right about the 2.5% result. I
> made a mistake.
>
> Lots of different ways to do this, but does this get you started?
>
> img3 = rgbImage((!img2)+img,img,img)
> display(img3)
>
> I tried the above commands. What I get appears to be the same as the
> original figure. Is there something that I am missing?
> Some of the stuff that I have tried are :
> I get this error message with the following command :
>
>> img4

Sorry, try this (note the added line to set pixels outside the band to 
0 in img2):

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!
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
#########Note must set all other pixels to 0######
img2[-crop]<-0
display(img2)

#Adds the band areas to the red channel
img3 = rgbImage((!img2)+img,img,img)
display(img3)

-- 
Alex Gutteridge



More information about the Bioconductor mailing list