hello... how to write a code for 0.7 membership threshold

1 view (last 30 days)
I am working on cardiac MRI LV images. I need a membership threshold to remove the unwanted area for images and give me only bright area inside in contours.

Answers (1)

Vidhi Agarwal
Vidhi Agarwal on 23 Sep 2024
Hi,
To isolate the bright regions within contours in cardiac MRI images, you can use a technique called fuzzy c-means clustering to determine membership thresholds. To achieve the aim, follow the given below steps:
  1. Use fuzzy c-means clustering to segment the image into different regions based on intensity.
  2. Use the membership values from the fuzzy c-means clustering to create a binary mask that isolates the bright regions.
Sample Code with above consideration is given below:
% Read the cardiac MRI image
image = imread('cardiac_mri.jpg'); % Replace with your image file
if size(image, 3) == 3
image = rgb2gray(image); % Convert to grayscale if necessary
end
% Enhance the contrast of the image
image = imadjust(image);
% Reshape the image for clustering
imageData = double(image(:));
% Apply fuzzy c-means clustering
numClusters = 3; % You can adjust the number of clusters
[centers, U] = fcm(imageData, numClusters);
% Find the cluster with the highest intensity
[~, maxClusterIdx] = max(centers);
% Get membership values for the brightest cluster
membershipValues = U(maxClusterIdx, :);
% Reshape membership values to the original image size
membershipImage = reshape(membershipValues, size(image));
% Threshold the membership image to create a binary mask
threshold = 0.7; % Adjust the threshold as needed
binaryMask = membershipImage > threshold;
% Postprocess the binary mask
binaryMask = imfill(binaryMask, 'holes'); % Fill holes
binaryMask = bwareaopen(binaryMask, 50); % Remove small objects
% Display the results
figure;
subplot(1, 3, 1), imshow(image), title('Original Image');
subplot(1, 3, 2), imshow(membershipImage, []), title('Membership Image');
subplot(1, 3, 3), imshow(binaryMask), title('Isolated Bright Region');
For given input image and above consideration the results are:
For better understanding of Fuzzy C-Means Clustering refer to the following documentation:
  • web(fullfile(docroot, "help/fuzzy/fcm.html"))
Hope that helps!

Categories

Find more on Fuzzy Logic Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!