Visualizing the region of classification uncertainty on thresholded images
1
0
Entering edit mode
Guest User ★ 13k
@guest-user-4897
Last seen 10.2 years ago
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! 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 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. 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.
PROcess PROcess • 1.5k views
ADD COMMENT
0
Entering edit mode
@alex-gutteridge-2935
Last seen 10.2 years ago
United States
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
ADD COMMENT
0
Entering edit mode
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<-channel(img2,'asred') Error in function (classes, fdef, mtable) : unable to find an inherited method for function "channel", for signature "Image", "character" You hint at several possible approaches. One alternative that I attempted was to assign NA to all those pixels that I wanted to be transparent. This did not give the result that I was after. One command that appears to be interesting is paintObjects which has an opacity parameter. But I am not able to figure out how I can use it in my case. Some other information on transparency that I have found is related to the alpha channel and raster images. I will havbe to dig into them to see if I can make use of those alternatives. It would help if you could just outline those alternatives that you think are promising. Thanks, Ravi Sutradhara [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
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
ADD REPLY
0
Entering edit mode
Hi Alex, Thanks a lot for your neat solution. Ravi ________________________________ From: Alex Gutteridge <alexg@ruggedtextile.com> Cc: Ravi [guest] <guest@bioconductor.org>; bioconductor@r-project.org; CRImage Maintainer <failmezger@cip.ifi.lmu.de> Sent: Tuesday, 7 August 2012, 15:51 Subject: Re: [BioC] Visualizing the region of classification uncertainty on thresholded images 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 [[elided Yahoo spam]] 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 [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
Hi Alex and list members, Can't help adding one more question. I would like to have a look at the image matrix corresponding to any particular particle and understand the nature of the mis-classification at the boundaries. How can I locate any particle that I am interested in? By the indices of the image matrix? I would then like to outline the region around it and extract the image intensity data. By looking at the same matrix in the threshold image, I hope to understand the nature of the errors in classification. Hope that this does not take up too much of your time. I am grateful for the help that I have received so far. Thanks, Ravi ________________________________ From: Alex Gutteridge <alexg@ruggedtextile.com> Cc: Ravi [guest] <guest@bioconductor.org>; bioconductor@r-project.org; CRImage Maintainer <failmezger@cip.ifi.lmu.de> Sent: Tuesday, 7 August 2012, 15:51 Subject: Re: [BioC] Visualizing the region of classification uncertainty on thresholded images 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 [[elided Yahoo spam]] 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 [[alternative HTML version deleted]]
ADD REPLY

Login before adding your answer.

Traffic: 738 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6