Noise Removing of an image matlab Code

Hi! Everyone i am new in matlab . I tried many process in matlab but can not get my desire output. Can anyone help me with some code that can remove image noise. The image is bellow. Please give me code to remove noise.. I need only white part and the other part will be black. Any help will be appreciated....... Thanks in advance...

3 Comments

Do you mean the white pixels as shown above, or the white part of the eye? And post your original gray scale or color image, and code to arrive at the binary image you showed, not a screenshot of a figure window. A screenshot is not that useful as far as trying anything goes.
Sorry sir, Its my first time so. And i got this figure using the adaptive clustering process the code is
function [lb,center] = adaptcluster_kmeans(im)
% This code is written to implement kmeans clustering for segmenting any % Gray or Color image. There is no requirement to mention the number of cluster for % clustering. % IM - is input image to be clustered. % LB - is labeled image (Clustered Image). % CENTER - is array of cluster centers. % Execution of this code is very fast. % It generates consistent output for same image.
if size(im,3)>1 [lb,center] = ColorClustering(im); % Check Image is Gray or not. else [lb,center] = GrayClustering(im); end
function [lb,center] = GrayClustering(gray) gray = double(gray); array = gray(:); % Copy value into an array. % distth = 25; i = 0;j=0; % Intialize iteration Counters. tic while(true) seed = mean(array); % Initialize seed Point. i = i+1; %Increment Counter for each iteration. while(true) j = j+1; % Initialize Counter for each iteration. dist = (sqrt((array-seed).^2)); % Find distance between Seed and Gray Value. distth = (sqrt(sum((array-seed).^2)/numel(array)));% Find bandwidth for Cluster Center. % distth = max(dist(:))/5; qualified = dist<distth;% Check values are in selected Bandwidth or not. newseed = mean(array(qualified));% Update mean.
if isnan(newseed) % Check mean is not a NaN value.
break;
end
if seed == newseed || j>10 % Condition for convergence and maximum iteration.
j=0;
array(qualified) = [];% Remove values which have assigned to a cluster.
center(i) = newseed; % Store center of cluster.
break;
end
seed = newseed;% Update seed.
end
if isempty(array) || i>10 % Check maximum number of clusters.
i = 0; % Reset Counter.
break;
end
end toc
center = sort(center); % Sort Centers. newcenter = diff(center);% Find out Difference between two consecutive Centers. intercluster = (max(gray(:)/10));% Findout Minimum distance between two cluster Centers. center(newcenter<=intercluster)=[];% Discard Cluster centers less than distance.
% Make a clustered image using these centers.
vector = repmat(gray(:),[1,numel(center)]); % Replicate vector for parallel operation. centers = repmat(center,[numel(gray),1]);
distance = ((vector-centers).^2);% Find distance between center and pixel value. [~,lb] = min(distance,[],2);% Choose cluster index of minimum distance. lb = reshape(lb,size(gray));% Reshape the labelled index vector.
function [lb,center] = ColorClustering(im)
im = double(im); red = im(:,:,1); green = im(:,:,2); blue = im(:,:,3);
array = [red(:),green(:),blue(:)]; % distth = 25; i = 0;j=0; tic while(true)
seed(1) = mean(array(:,1));
seed(2) = mean(array(:,2));
seed(3) = mean(array(:,3));
i = i+1;
while(true)
j = j+1;
seedvec = repmat(seed,[size(array,1),1]);
dist = sum((sqrt((array-seedvec).^2)),2);
distth = 0.25*max(dist);
qualified = dist<distth;
newred = array(:,1);
newgreen = array(:,2);
newblue = array(:,3);
newseed(1) = mean(newred(qualified));
newseed(2) = mean(newgreen(qualified));
newseed(3) = mean(newblue(qualified));
if isnan(newseed)
break;
end
if (seed == newseed) | j>10
j=0;
array(qualified,:) = [];
center(i,:) = newseed;
% center(2,i) = nnz(qualified);
break;
end
seed = newseed;
end
if isempty(array) || i>10
i = 0;
break;
end
end toc centers = sqrt(sum((center.^2),2)); [centers,idx]= sort(centers);
while(true) newcenter = diff(centers); intercluster =25; %(max(gray(:)/10)); a = (newcenter<=intercluster); % center(a,:)=[]; % centers = sqrt(sum((center.^2),2)); centers(a,:) = []; idx(a,:)=[]; % center(a,:)=0; if nnz(a)==0 break; end
end center1 = center; center =center1(idx,:); % [~,idxsort] = sort(centers) ; vecred = repmat(red(:),[1,size(center,1)]); vecgreen = repmat(green(:),[1,size(center,1)]); vecblue = repmat(blue(:),[1,size(center,1)]);
distred = (vecred - repmat(center(:,1)',[numel(red),1])).^2; distgreen = (vecgreen - repmat(center(:,2)',[numel(red),1])).^2; distblue = (vecblue - repmat(center(:,3)',[numel(red),1])).^2;
distance = sqrt(distred+distgreen+distblue); [~,label_vector] = min(distance,[],2); lb = reshape(label_vector,size(red)); %
and the color image is
I need to segment the sclera part from the image. I am doing sclera recognition project. If you have any matlab code for this please help. And thanks for reply.

Sign in to comment.

 Accepted Answer

8 Comments

See attached demo (test.m at the very bottom), taken from my file exchange, adapted to find white. it will produce this image (on its second screen):
You can see from this 3D color gamut:
that kmeans would not necessarily be great for color segmentation, and especially not after you've converted to gray scale. So I would not use the approach you mentioned.
Thank you so much for your help sir.
Asif Hasan
Asif Hasan on 21 May 2014
Edited: Asif Hasan on 21 May 2014
Sir,
Would you please brief me about the code that you gave me so that i can understand.When i run following image through the code i got a white section upside the eye but i can't understand how to modify it. So give me some idea so that i do my work and sir how do you measure the red color?
Yes, some of the eyelid is white, and so it finds that region. Try adjusting some of the parameters or look for successful published algorithms here: http://www.visionbib.com/bibliography/contents.html
Asif Hasan
Asif Hasan on 29 Aug 2014
Edited: Asif Hasan on 29 Aug 2014
@Image Analist Sir, You provided me a code that can segment sclera from eye image
but when i input this image it can't give me the result. What should i do?
Keep working on it. Did you see the link to papers from people have have presumably solved it? It looks like color alone won't solve it if you need to find sclera that is reddish so you may have to combine with other methods like spatial location or edge detection. Maybe you have to locate the iris first and look outwards from there. I can see that it could be a very challenging problem to automatically get every possible pathological image absolutely correct. As a last resort you may have to resort to using imfreehand(). Let me know if you want a demo of that. The good thing is that if you resort to doing it manually, there aren't many images since each patient will have only a few images at most, not hundreds or thousands.
Thanks for the reply . But which one should i follow first for this kind of problem , there are many links. @Image Analist
Follow the ones that sound most promising. I have not read all the image processing papers in that narrow field, or even any of them, so I don't know which are any good. You'll have to figure that out on your own.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!