http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059
MATLAB Central Newsreader  ROC curve of target and source images
Feed for thread: ROC curve of target and source images
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 25 Feb 2013 12:06:08 +0000
ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#898667
Carl S.
Hi,<br>
<br>
I need matlab codes to plot a roc curve of target and source images<br>
<br>
(I have searched but the files in FileExchange are not clear (not get image files as input to give the plotted curve) for my purpose)

Mon, 25 Feb 2013 19:19:09 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#898694
Carl S.
"Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> Hi,<br>
> <br>
> I need matlab codes to plot a roc curve of target and source images<br>
> <br>
> (I have searched but the files in FileExchange are not clear (not get image files as input to give the plotted curve) for my purpose)<br>
<br>
Hi,<br>
I have seen the following function;<br>
[tpr,fpr,thresholds] = roc(Targets, Outputs)<br>
<br>
I think this function gives the parameters to draw ROC curves, such as true positive, false negative... But, how to obtain the input parameters from png file images ?

Tue, 26 Feb 2013 11:50:07 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#898724
Carl S.
"Carl S." wrote in message <kggdfd$51j$1@newscl01ah.mathworks.com>...<br>
> "Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> > Hi,<br>
> > <br>
> > I need matlab codes to plot a roc curve of target and source images<br>
> > <br>
> > (I have searched but the files in FileExchange are not clear (not get image files as input to give the plotted curve) for my purpose)<br>
> <br>
> Hi,<br>
> I have seen the following function;<br>
> [tpr,fpr,thresholds] = roc(Targets, Outputs)<br>
> <br>
> I think this function gives the parameters to draw ROC curves, such as true positive, false negative... But, how to obtain the input parameters from png file images ?<br>
<br>
I have performed the following process:<br>
1) I have applied Dice similarity measurement for automatically segmented images and obtained the following similarity coefficients<br>
<br>
image1 0.8313<br>
image2 0.9157<br>
image3 0.9328<br>
image4 0.7790<br>
image5 0.8547<br>
image6 0.7026<br>
<br>
2) I have chosen 0.7 as the threshold value, and wrote the following codes<br>
scores = [0.8313 0.9157 0.9328 0.7790 0.8547 0.7026]<br>
labels = [1 1 1 0 1 0] % <= Here, ones corresponds to positive (acceptable coefficient, zero corresponds to negative (not acceptable)<br>
ROC(scores,labels);<br>
<br>
The ROC function gives the TP and FP values and also draw the ROC curve. But the result is not good, although there is only two image that have zero label. So, the ROC curve is not correct. I still need a help, and it is urgent please :(<br>
<br>
function<br>
[Tps, Fps] = ROC(scores, labels) <br>
%% Sort Labels and Scores by Scores<br>
sl = [scores; labels];<br>
[d1 d2] = sort(sl(1,:));<br>
sorted_sl = sl(:,d2);<br>
s_scores = sorted_sl(1,:);<br>
s_labels = round(sorted_sl(2,:));<br>
%% Constants<br>
counts = histc(s_labels, unique(s_labels));<br>
Tps = zeros(1, size(s_labels,2) + 1);<br>
Fps = zeros(1, size(s_labels,2) + 1);<br>
negCount = counts(1);<br>
posCount = counts(2);<br>
%% Shift threshold to find the ROC<br>
for<br>
thresIdx = 1:(size(s_scores,2)+1) <br>
% for each Threshold Index <br>
tpCount = 0;<br>
fpCount = 0;<br>
for i = [1:size(s_scores,2)] <br>
if (i >= thresIdx) % We think it is positive <br>
if (s_labels(i) == 1) % Right! <br>
tpCount = tpCount + 1;<br>
else % Wrong! <br>
fpCount = fpCount + 1;<br>
end <br>
end <br>
end <br>
Tps(thresIdx) = tpCount/posCount;<br>
Fps(thresIdx) = fpCount/negCount;<br>
end<br>
%% Draw the Curve<br>
% Sort [Tps;Fps]<br>
x = Tps;<br>
y = Fps;<br>
% Interplotion to draw spline line<br>
count = 100;<br>
dist = (x(1)  x(size(x,2)))/100;<br>
xx = [x(1):dist:x(size(x,2))];<br>
% In order to get the interpolations, we remove all the unique numbers<br>
[d1 d2] = unique(x);<br>
uni_x = x(1,d2);<br>
uni_y = y(1,d2);<br>
yy = spline(uni_x,uni_y,xx);<br>
% No value should exceed 1<br>
yy = min(yy, 1);<br>
plot(x,y,'x',xx,yy);

Wed, 27 Feb 2013 00:41:08 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#898761
Alan B
> "Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> I have performed the following process:<br>
> 1) I have applied Dice similarity measurement for automatically segmented images and obtained the following similarity coefficients<br>
<br>
ROC curves are more generally applicable than just your application, so it is not clear what you expect your function to do. If you want help, you might want to try explaining what you are trying to do in more detail.

Wed, 27 Feb 2013 03:25:07 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#898765
Carl S.
"Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgjkn4$b5j$1@newscl01ah.mathworks.com>...<br>
> > "Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> > I have performed the following process:<br>
> > 1) I have applied Dice similarity measurement for automatically segmented images and obtained the following similarity coefficients<br>
> <br>
> ROC curves are more generally applicable than just your application, so it is not clear what you expect your function to do. If you want help, you might want to try explaining what you are trying to do in more detail.<br>
<br>
Thanks Alan,<br>
I would like to compare different segmentation algorithms. I have obtained segmented images from these algorithms. I have manually segmented images. I want to draw ROC curve. To draw ROC curve, I need some values such as positive true, negative true values. When I searched matlab functions to obtain these values, the functions ask Label and Scores. But I dont know how can I decide the labels and scores. Think that you have segmented brain image. How can you decide ?<br>
<br>
Shortly, I have automatically segmented images obtained from different algorithms. And manually segmented reference images. Now, I need an application that gets these images as input and draws ROC curves.<br>
Help me pls

Fri, 01 Mar 2013 17:03:08 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#899007
Alan B
"Carl S." wrote in message <kgjuaj$6d3$1@newscl01ah.mathworks.com>...<br>
> "Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgjkn4$b5j$1@newscl01ah.mathworks.com>...<br>
> > > "Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> > > I have performed the following process:<br>
> > > 1) I have applied Dice similarity measurement for automatically segmented images and obtained the following similarity coefficients<br>
> > <br>
> > ROC curves are more generally applicable than just your application, so it is not clear what you expect your function to do. If you want help, you might want to try explaining what you are trying to do in more detail.<br>
> <br>
> Thanks Alan,<br>
> I would like to compare different segmentation algorithms. I have obtained segmented images from these algorithms. I have manually segmented images. I want to draw ROC curve. To draw ROC curve, I need some values such as positive true, negative true values. When I searched matlab functions to obtain these values, the functions ask Label and Scores. But I dont know how can I decide the labels and scores. Think that you have segmented brain image. How can you decide ?<br>
> <br>
> Shortly, I have automatically segmented images obtained from different algorithms. And manually segmented reference images. Now, I need an application that gets these images as input and draws ROC curves.<br>
> Help me pls<br>
<br>
This isn't a matlabspecific question; there are several different ways you might do that. If you can explain exactly what algorithm you are trying to implement, then you can expect an answer here. If you aren't sure what algorithm is appropriate to use for your problem, then your teacher/boss/reference paper is a better place to get that information.

Sat, 02 Mar 2013 18:56:05 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#899058
Carl S.
"Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgqn0c$8pv$1@newscl01ah.mathworks.com>...<br>
> "Carl S." wrote in message <kgjuaj$6d3$1@newscl01ah.mathworks.com>...<br>
> > "Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgjkn4$b5j$1@newscl01ah.mathworks.com>...<br>
> > > > "Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> > > > I have performed the following process:<br>
> > > > 1) I have applied Dice similarity measurement for automatically segmented images and obtained the following similarity coefficients<br>
> > > <br>
> > > ROC curves are more generally applicable than just your application, so it is not clear what you expect your function to do. If you want help, you might want to try explaining what you are trying to do in more detail.<br>
> > <br>
> > Thanks Alan,<br>
> > I would like to compare different segmentation algorithms. I have obtained segmented images from these algorithms. I have manually segmented images. I want to draw ROC curve. To draw ROC curve, I need some values such as positive true, negative true values. When I searched matlab functions to obtain these values, the functions ask Label and Scores. But I dont know how can I decide the labels and scores. Think that you have segmented brain image. How can you decide ?<br>
> > <br>
> > Shortly, I have automatically segmented images obtained from different algorithms. And manually segmented reference images. Now, I need an application that gets these images as input and draws ROC curves.<br>
> > Help me pls<br>
> <br>
> This isn't a matlabspecific question; there are several different ways you might do that. If you can explain exactly what algorithm you are trying to implement, then you can expect an answer here. If you aren't sure what algorithm is appropriate to use for your problem, then your teacher/boss/reference paper is a better place to get that information.<br>
<br>
Thanks Alan,<br>
I have implemented an algorithm to draw ROC curves and to obtain accuracy value by using grayscale test and target images. But I think, the results are not ture since it give %90 accuracy when the test image seems very different. Could you please help me where the mistake is in the following codes:<br>
<br>
TargetMask = zeros(size(TargetImg(:,:,1)));<br>
TargetMask = TargetImg(:,:,1)>0;<br>
NotTargetMask = logical(1TargetMask);<br>
<br>
TestMask = zeros(size(TestImg));<br>
TestMask= TestImg>0;<br>
<br>
FPimg = TestMask.*NotTargetMask<br>
FPcounts = sum(FPimg);<br>
FP = sum(FPimg(:))<br>
<br>
TPimg = TestMask.*TargetMask<br>
TPcounts = sum(TPimg);<br>
TP = sum(TPimg(:))<br>
<br>
FNimg = TargetMaskTPimg<br>
FNcounts = sum(FNimg);<br>
FN = sum(FNimg(:))<br>
<br>
TNimg = 1 FPimg<br>
TNcounts = sum(TNimg);<br>
TN =sum(TNimg(:))<br>
<br>
FP_TNcounts = FPcounts + TNcounts;<br>
TP_FNcounts = FNcounts + TPcounts;<br>
<br>
FP_TNcounts(find(FP_TNcounts==0))=1e10; % to solve divide by zero error<br>
TP_FNcounts(find(TP_FNcounts==0))=1e10; % to solve divide by zero error<br>
<br>
FPrate(:,:,i) = FPcounts./FP_TNcounts; % 1specifisity<br>
TPrate(:,:,i) = TPcounts./TP_FNcounts; % sensitivity

Mon, 04 Mar 2013 10:06:05 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#899123
Carl S.
"Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgqn0c$8pv$1@newscl01ah.mathworks.com>...<br>
> "Carl S." wrote in message <kgjuaj$6d3$1@newscl01ah.mathworks.com>...<br>
> > "Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgjkn4$b5j$1@newscl01ah.mathworks.com>...<br>
> > > > "Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> > > > I have performed the following process:<br>
> > > > 1) I have applied Dice similarity measurement for automatically segmented images and obtained the following similarity coefficients<br>
> > > <br>
> > > ROC curves are more generally applicable than just your application, so it is not clear what you expect your function to do. If you want help, you might want to try explaining what you are trying to do in more detail.<br>
> > <br>
> > Thanks Alan,<br>
> > I would like to compare different segmentation algorithms. I have obtained segmented images from these algorithms. I have manually segmented images. I want to draw ROC curve. To draw ROC curve, I need some values such as positive true, negative true values. When I searched matlab functions to obtain these values, the functions ask Label and Scores. But I dont know how can I decide the labels and scores. Think that you have segmented brain image. How can you decide ?<br>
> > <br>
> > Shortly, I have automatically segmented images obtained from different algorithms. And manually segmented reference images. Now, I need an application that gets these images as input and draws ROC curves.<br>
> > Help me pls<br>
> <br>
> This isn't a matlabspecific question; there are several different ways you might do that. If you can explain exactly what algorithm you are trying to implement, then you can expect an answer here. If you aren't sure what algorithm is appropriate to use for your problem, then your teacher/boss/reference paper is a better place to get that information.<br>
<br>
I have updated the codes but still the results are unexpected :(( <br>
Could you PLEASE run the following codes for your images and inform me whether you get correct results or not. I need your help<br>
<br>
clear all; close all;<br>
<br>
TargetImg=imread('GRAYSCALEref.png');<br>
Test(:,:,1)=imread('GRAYSCALEtest1.png');<br>
Test(:,:,2)=imread('GRAYSCALEtest2.png');<br>
<br>
[u v]=size(TargetImg);<br>
TPrate=zeros(1, u, 2); FPrate=zeros(1, u, 2); <br>
<br>
for i=1:2 <br>
<br>
TestImg=Test(:,:,i); <br>
<br>
TargetMask = zeros(size(TargetImg(:,:,1)));<br>
TargetMask = TargetImg(:,:,1)>0;<br>
NotTargetMask = logical(1TargetMask);<br>
<br>
TestMask = zeros(size(TestImg));<br>
TestMask= TestImg>0;<br>
<br>
FPimg = TestMask.*NotTargetMask<br>
FP = sum(FPimg(:))<br>
<br>
TPimg = TestMask.*TargetMask<br>
TP = sum(TPimg(:))<br>
<br>
FNimg = TargetMaskTPimg<br>
FN = sum(FNimg(:))<br>
<br>
TNimg = 1 FPimg<br>
TN =sum(TNimg(:))<br>
<br>
TPrate(1,:,i)=TP/(TP+FN);<br>
FPrate(1,:,i)=FP/(FP+TN);<br>
<br>
Sensitivity(i)= TP/(TP+FN)*100 <br>
Specificity(i)= TN/(TN+FP)*100 <br>
Accuracy(i)=(TP+TN)/(TP+TN+FN+FP)*100 <br>
<br>
end<br>
plot(sort(FPrate(:,:,1)), sort(TPrate(:,:,1)),'y','LineWidth',3); <br>
plot(sort(FPrate(:,:,2)), sort(TPrate(:,:,2)),'g','LineWidth',3); <br>
axis([0:1,0:1]);

Mon, 04 Mar 2013 17:32:09 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#899159
S C.Carl
"S C.Carl" wrote in message <kh1rmd$9n8$1@newscl01ah.mathworks.com>...<br>
> "Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgqn0c$8pv$1@newscl01ah.mathworks.com>...<br>
> > "Carl S." wrote in message <kgjuaj$6d3$1@newscl01ah.mathworks.com>...<br>
> > > "Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <kgjkn4$b5j$1@newscl01ah.mathworks.com>...<br>
> > > > > "Carl S." wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> > > > > I have performed the following process:<br>
> > > > > 1) I have applied Dice similarity measurement for automatically segmented images and obtained the following similarity coefficients<br>
> > > > <br>
> > > > ROC curves are more generally applicable than just your application, so it is not clear what you expect your function to do. If you want help, you might want to try explaining what you are trying to do in more detail.<br>
> > > <br>
> > > Thanks Alan,<br>
> > > I would like to compare different segmentation algorithms. I have obtained segmented images from these algorithms. I have manually segmented images. I want to draw ROC curve. To draw ROC curve, I need some values such as positive true, negative true values. When I searched matlab functions to obtain these values, the functions ask Label and Scores. But I dont know how can I decide the labels and scores. Think that you have segmented brain image. How can you decide ?<br>
> > > <br>
> > > Shortly, I have automatically segmented images obtained from different algorithms. And manually segmented reference images. Now, I need an application that gets these images as input and draws ROC curves.<br>
> > > Help me pls<br>
> > <br>
> > This isn't a matlabspecific question; there are several different ways you might do that. If you can explain exactly what algorithm you are trying to implement, then you can expect an answer here. If you aren't sure what algorithm is appropriate to use for your problem, then your teacher/boss/reference paper is a better place to get that information.<br>
> <br>
> I have updated the codes but still the results are unexpected :(( <br>
> Could you PLEASE run the following codes for your images and inform me whether you get correct results or not. I need your help<br>
> <br>
> clear all; close all;<br>
> <br>
> TargetImg=imread('GRAYSCALEref.png');<br>
> Test(:,:,1)=imread('GRAYSCALEtest1.png');<br>
> Test(:,:,2)=imread('GRAYSCALEtest2.png');<br>
> <br>
> [u v]=size(TargetImg);<br>
> TPrate=zeros(1, u, 2); FPrate=zeros(1, u, 2); <br>
> <br>
> for i=1:2 <br>
> <br>
> TestImg=Test(:,:,i); <br>
> <br>
> TargetMask = zeros(size(TargetImg(:,:,1)));<br>
> TargetMask = TargetImg(:,:,1)>0;<br>
> NotTargetMask = logical(1TargetMask);<br>
> <br>
> TestMask = zeros(size(TestImg));<br>
> TestMask= TestImg>0;<br>
> <br>
> FPimg = TestMask.*NotTargetMask<br>
> FP = sum(FPimg(:))<br>
> <br>
> TPimg = TestMask.*TargetMask<br>
> TP = sum(TPimg(:))<br>
> <br>
> FNimg = TargetMaskTPimg<br>
> FN = sum(FNimg(:))<br>
> <br>
> TNimg = 1 FPimg<br>
> TN =sum(TNimg(:))<br>
> <br>
> TPrate(1,:,i)=TP/(TP+FN);<br>
> FPrate(1,:,i)=FP/(FP+TN);<br>
> <br>
> Sensitivity(i)= TP/(TP+FN)*100 <br>
> Specificity(i)= TN/(TN+FP)*100 <br>
> Accuracy(i)=(TP+TN)/(TP+TN+FN+FP)*100 <br>
> <br>
> end<br>
> plot(sort(FPrate(:,:,1)), sort(TPrate(:,:,1)),'y','LineWidth',3); <br>
> plot(sort(FPrate(:,:,2)), sort(TPrate(:,:,2)),'g','LineWidth',3); <br>
> axis([0:1,0:1]); <br>
<br>
The values from my target and test images , which have the same size (256,256), from the above codes are :<br>
<br>
TP = 1371<br>
FN = 205<br>
FP = 12171<br>
TN = 51789<br>
<br>
As you see, FP is high (means that classifier indicates some pixels as foreground but they are actually background). Therefore, I guess that the accuracy is lower than about 50%, but the formula, Accuracy=(TP+TN)/(TP+TN+FN+FP)*100 gives the result as 81.11. <br>
Similarly, sensitivity and specificity values are 86.99 and 80.97, which are too high for this test image<br>
<br>
According to these metrics the classifier is successful. But the foreground on the test image seems very different from the foreground on the target image. I mean the classifier is not successful but the results do not say the same thing. WHY ? Please correct me<br>
if I wrong (Note: I used zero as the threshold value to separate the foreground(grayscale) and background that is already zero)<br>
<br>
My other question is that the following codes<br>
> TPrate(1,:,i)=TP/(TP+FN);<br>
> FPrate(1,:,i)=FP/(FP+TN);<br>
give a point. I would like to see the curve. How to draw the curve ?

Tue, 24 Sep 2013 06:32:06 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#911642
Ashraful Alam
Can true positive and true negative measure applied in COLOR image. That means, i segment an color MRI image by fuzzy clustering method, now if i want to measure the true positive and true negative number of pixel, how can i do it? pls help......<br>
thanksation <br>
Ashraful Alam

Fri, 14 Mar 2014 10:46:08 +0000
Re: ROC curve of target and source images
http://www.mathworks.com/matlabcentral/newsreader/view_thread/327059#919607
Anitha
"S C.Carl" wrote in message <kgfk3g$9i5$1@newscl01ah.mathworks.com>...<br>
> Hi,<br>
> <br>
> I need matlab codes to plot a roc curve of target and source images<br>
> <br>
> (I have searched but the files in FileExchange are not clear (not get image files as input to give the plotted curve) for my purpose)<br>
<br>
Hi,<br>
<br>
Did u get the solution for drawing ROC curve between Ground truth and the segmented image