In order to obtain the optimal threshold for the ROC curve, it is necessary to use a metric - Jordon's index, also known as the correct index.
The calculation can be derived with the help of matlab's roc function.
% 1-specificity = fpr % Sensitivity = tpr; [tpr,fpr,thresholds] =roc(Tar',Val'); RightIndex=(tpr+(1-fpr)-1); [~,index]=max(RightIndex); % RightIndexVal=RightIndex(index(1)); tpr_val=tpr(index(1)); fpr_val=fpr(index(1)); thresholds_val=thresholds(index(1)); disp([' Average accuracy: ',num2str((RightIndexVal+1)*0.5)]); disp(['Best rate of correctness: ',num2str(tpr_val)]) disp(['Optimal error rate: ',num2str(fpr_val)])
This concludes the calculation.
Additional extensions: segmenting target images using thresholding
I. Global thresholds
Methodology I: OTSU methodology
The otsu method (maximum interclass variance method, sometimes called Otsu algorithm) uses the idea of clustering to divide the number of grays of an image into 2 parts according to the gray level, so that the difference in gray value between the two parts is the largest, and the difference in gray between each part is the smallest, and the variance is computed to find a suitable gray level to divide. So the otsu algorithm can be used in binarization to automatically select the threshold for binarization. otsu algorithm is considered as the best algorithm for threshold selection in image segmentation, which is simple to compute and is not affected by the brightness and contrast of the image. Thus, segmentation that maximizes the variance between classes implies minimum probability of misclassification.
The threshold k is chosen to categorize the pixels into two classes:
T=graythresh(f) can be implemented to compute the normalized threshold using method one.
II. Localized thresholds
When the background illumination is not uniform, the global thresholding method may fail, in which case the image f(x,y) is segmented with a locally varying threshold function T(x,y):
matlab implementation of the program:
clear all;close all;clc; I=imread('C:\Users\ASUS\Desktop\Image Processing Study Files\second half of sophomore year\Segmenting Targets Using Thresholds_15\Fig0926(a)(rice).tif'); figure imshow(I) title('original image') k=graythresh(I); I1=im2bw(I,k); figure imshow(I1) se=strel('disk',10); %generates a radius of10disk-shaped structural element fo=imopen(I1,se); %Open operations on grayscale images with structural elements figure imshow(fo) title('Opened image') f2=imtophat(I,se); %Subtract the open operation image from the original image,That is, the top-hat operation on the image figure imshow(f2,[]) %Displaying the results of top hat operations title('Top-hat transformation') f2=im2double(f2); T=graythresh(f2); bw2=im2bw(f2,T); %Thresholding of top-hat processed images figure imshow(bw2,[]) title('Thresholded top-hat image') %Display of thresholded top hat image
The above article on how to select the optimal threshold of the ROC curve is all I have shared with you, I hope it can give you a reference, and I hope you will support me more.