%% Step 1: Initialize clc; clear; %% Step 2: Load Input CT Images function images = load_images(dataset_path) image_files = dir(fullfile(dataset_path, '*.png')); if isempty(image_files) image_files = dir(fullfile(dataset_path, '*.jpg')); end images = cell(1, numel(image_files)); for i = 1:numel(image_files) images{i} = imread(fullfile(dataset_path, image_files(i).name)); end end images = load_images('dataset_path'); %% Step 3: Pre-Processing (Image Enhancement) function enhanced = median_filter(image) enhanced = medfilt2(image); end enhanced_images = cellfun(@median_filter, images, 'UniformOutput', false); %% Step 4: Segmentation using Multilevel Thresholding and PSO function gray = convert_to_grayscale(image) if size(image,3) == 3 gray = rgb2gray(image); else gray = image; end end function thresholds = otsu_thresholding(image) thresholds = graythresh(image); end function optimal_thresholds = PSO_optimize_thresholds(image, initial_thresholds) % Placeholder PSO implementation optimal_thresholds = initial_thresholds; % Dummy placeholder end function segmented = apply_thresholds(image, thresholds) segmented = imbinarize(image, thresholds); end segmented_images = cell(1, numel(enhanced_images)); for i = 1:numel(enhanced_images) gray_img = convert_to_grayscale(enhanced_images{i}); init_thresh = otsu_thresholding(gray_img); opt_thresh = PSO_optimize_thresholds(gray_img, init_thresh); segmented_images{i} = apply_thresholds(gray_img, opt_thresh); end %% Step 5: Feature Extraction and Classification using CNN function model = load_trained_CNN_model(model_path) % Placeholder for CNN model loading load(model_path, 'model'); end function features = extract_features(model, image) % Placeholder CNN feature extraction features = activations(model, image, 'fc'); end function label = classify_CNN(model, features) % Placeholder classification score = mean(features(:)); if score > 0.5 label = 'Malignant'; else label = 'Benign'; end end trained_CNN = load_trained_CNN_model('model_path'); classification_results = cell(1, numel(segmented_images)); for i = 1:numel(segmented_images) features = extract_features(trained_CNN, segmented_images{i}); classification_results{i} = classify_CNN(trained_CNN, features); end %% Step 6: Performance Evaluation function metrics = evaluate_performance(predictions, ground_truth) TP = sum(strcmp(predictions, 'Malignant') & strcmp(ground_truth, 'Malignant')); TN = sum(strcmp(predictions, 'Benign') & strcmp(ground_truth, 'Benign')); FP = sum(strcmp(predictions, 'Malignant') & strcmp(ground_truth, 'Benign')); FN = sum(strcmp(predictions, 'Benign') & strcmp(ground_truth, 'Malignant')); sensitivity = TP / (TP + FN); specificity = TN / (TN + FP); accuracy = (TP + TN) / numel(predictions); metrics = struct('Sensitivity', sensitivity, 'Specificity', specificity, 'Accuracy', accuracy); end ground_truth_labels = {}; % Add actual labels here metrics = evaluate_performance(classification_results, ground_truth_labels); %% Step 7: Display Results for i = 1:numel(segmented_images) figure; subplot(1,2,1), imshow(images{i}), title('Original Image'); subplot(1,2,2), imshow(segmented_images{i}), title('Segmented Image'); end disp('Performance Metrics:'); disp(metrics);