File Exchange

image thumbnail

Wavelet Based Image Segmentation

version 2.7.0.0 (1.62 MB) by Ashutosh Kumar Upadhyay
Segment image containing blobs of various intensities and shapes in noisy inhomogenous background

11 Downloads

Updated 30 Dec 2016

View License

This code is a part of our work "Nonseparable Wavelet Based Segmentation ..." . It contains the methods to extract out the darker or lighter blobs (spots) of various intensities and shapes (including faint/ low intensity spots) from noisy or inhomogeneous background. The method is designed for segmenting the protein blobs from 2D gel images. The other suitable images are quantum dot images, images of cirucular objects in noisy inhomogneous background, malaria parasite images, oil blobs on sea/river, fluroscence cell images similar to http://www.robots.ox.ac.uk/~vgg/research/counting/, dermoscopy images etc. The kernel-bandwidth and contrast threshold are two parameter that may need to change according to the image. For 2D gel images, you may vary only contrast threshold for your dataset although no change is required in any parameter in case of 2D gel images. The little modification in region refinement part according to an application may segment many other type of images such as some type of microarray images.

Cite As

Ashutosh Kumar Upadhyay (2020). Wavelet Based Image Segmentation (https://www.mathworks.com/matlabcentral/fileexchange/48610-wavelet-based-image-segmentation), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (37)

lucky he

Hello Ashutosh.Do you have a noiseless version of the 'syn_16_20_3.bmp' picture? If convenient, please send it to my email(xhdd9278@163.com), thank you very much, in addition, is it convenient for you to provide the source of this code.thank you!

Please Please Please help me

Error using litekmeans (line 189)
X must have more rows than the number of clusters.

Error in WaveletBasedImageSegmentation (line 226)
u =litekmeans(mm',2);u=u(:); id1=find(u==1);c1=sum(mm(id1))/length(id1); id2=find(u==2);
c2=sum(mm(id2))/length(id2);[c3 c4]=min([c1 c2]); idx2=find(u==c4);

while running i got error like this...pls help me to debug.

Nivashini V

Error using -
Matrix dimensions must agree.

Error in litekmeans>init (line 27)
[~,label] =
min(dot(mu,mu,1)'/2-mu'*X,[],1);

Error in litekmeans (line 12)
label = init(X, m);

Error in WaveletBasedImageSegmentation
(line 226)
u =litekmeans(mm',2);u=u(:);
id1=find(u==1);c1=sum(mm(id1))/length(id1);
id2=find(u==2);
c2=sum(mm(id2))/length(id2);[c3
c4]=min([c1 c2]); idx2=find(u==c4);
>> while running i got error like this...pls help me to debug.

Nathan Zhang

Dear Jin,
getoptions() function is in toolbox_wavelets/toolbox folder. Update the path in matlab. or On internet, follow this link
https://in.mathworks.com/matlabcentral/fileexchange/5104-toolbox-wavelets, click on function tab and search getoptions, copy & paste in new file and save in same location where perform_quincunx...... is located.

I have this error.

Undefined function 'getoptions' for input arguments of type 'struct'.

Error in perform_quicunx_wavelet_transform_ti (line 34)
bound = getoptions(options, 'bound', 'per');

Error in WaveletBasedImageSegmentation2 (line 125)
MW=perform_quicunx_wavelet_transform_ti(M,1,options);

How could it be solved?

Thanks

karthik sa

The function "get_quincunx_filter" was closed with an 'end', but at least one other function definition was not. To avoid
confusion when using nested functions, it is illegal to use both conventions in the same file. how to clear this error Pls help

In WaveletBasedImageSegmentation.m (line 223) the command line “% and rename it as litekmeans.m to distinguish it from matlab kmeans” was change by “% and rename it as litekmeans.m to distinguish it from matlab kseeds”.

In WaveletBasedImageSegmentation.m (line 349) the command line “L=L.* double(bb4>0);” was change by “L=double(L).* double(bb4>0);”.

This algo just find out brighter or darker blobs in the images and then the obtained blobs can be refined using morphological operations. This algo is limited to the images where our purpose is to segment out the darker or brighter objects in the images, especially when there is uneven background and simple methods don't work.

Is Wavelet Based Image Segmentation the same thing as image morphological segmentation?

z hasanpoor

The folders and subfolders of kmeans clustering and toolbox wavelet should be added to matlab path.

I have a question beginner. When download the kmeans-clustering, where should I put? When I compiled presented the following problem

Error in WaveletBasedImageSegmentation (line 133)
Perform_quicunx_wavelet_transform_ti MW = (M 1, options);

How should I solve?

litekmeans is now kmeans only. please download it from http://in.mathworks.com/matlabcentral/fileexchange/24616-kmeans-clustering/content/kmeans/kmeans.m

and change the name at one of places (either at function name or at function call in our program).

Jurgen

Dear author, the function litekmeans is not part of the fileexchange submission linked in the description. The author may have changed the names?

Hello Ashutosh.
The Description says that the code is from the paper which is submitted. But I can't find it. Is it published? How can I find it?
Thank you!

Oto Ha

Hello Ashutosh.

I have this error.

Undefined function 'getoptions' for input arguments of type 'struct'.

Error in perform_quicunx_wavelet_transform_ti (line 34)
bound = getoptions(options, 'bound', 'per');

Error in WaveletBasedImageSegmentation2 (line 125)
MW=perform_quicunx_wavelet_transform_ti(M,1,options);

How could it be solved?

Thanks

Dear Amine,
sorry you got error due to requirement of strict typecasting in matalab newer versions. Check the datatype of L, by typing class(L), It is double. So a typecasting with
'double' is required with bb4.
try this:
L=L.* double(bb4);

Amine

Dear Ashutosh,

I got this error on Matlab r2015b:
"Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in WaveletBasedImageSegmentation (line 349)
L=L.*(bb4>0); %%% Thanx to Justin Du..."

Thanks for sharing

Dear Justin Du,

Thanks a lot for your cooperation and efforts. Your screenshots, comments and suggestions are really helpful to solve the problem. Since I was not getting the error on my system, it was totally impossible task for me to remove such an error.

Thanks.

Dear All,
Please modify the litekmeans code as described in the comment by David on its download page.

If you are getting error on your computer while calling litekmeans, you can call matlab inbuild kmeans.

To use the matlab inbuild k-means, please uncomment the line no. 216.
%[u v]=kmeans(mm,2,'Start',[min(mm); max(mm)], 'Maxiter', 1000); c1=v(1); c2=v(2);[c3 c4]=min(v); idx2=find(u==c4);

Please also comment the line no. 226 which calls litekmeans. And also uncomment the line no. 196.

Hope it will help.

Yixin Du

Hi Ashutosh, I always got the same error as Van. I tried to uncomment the "%continue". It still doesn't work. Could you please send a solution to this problem to justduin@gmail.com? Thank you very much.

Dear Van,
if you find out that error is due to mm', the 'continue' written in following line before calling litekmeans can be uncommented.
%%Following condition is needed for numerical implementation/ for calling k-means and you can try.
if(length(rr)< smallR*smallR) %%noisy pixels only, less than size of object. may create problem for matlab k-means
%continue;
end

Dear Van, yes it may be, it may be that mm' is empty somehow and it is not checked before calling litekmeans. Therefore, to check this condition, i suggest to add following lines to find out the size of vectors,
size(X)
size(k)
size(label).
If it doesn't indicate anything wrong, and error is coming then please tell me.

Ok, thank you very much. But I think that it has an error when execute command "u =litekmeans(mm',2);" in the WaveletBasedImageSegmentation function (line 226)

Dear Van,
Please insert the lines before while loop, to find out the size of vectors and source of error. The code of litekmeans.m now should be like this:

function label = litekmeans(X, k)
% Perform k-means clustering.
% X: d x n data matrix
% k: number of seeds
% Written by Michael Chen (sth4nth@gmail.com)on matlab central.
n = size(X,2);
last = 0;
label = ceil(k*rand(1,n)); % random initialization
size(X)
size(k)
size(label)
while any(label ~= last)
[u,v,label] = unique(label); % remove empty clusters
k = length(u);
E = sparse(1:n,label,1,n,k,n); % transform label into indicator matrix
m = X*(E*spdiags((1./sum(E,1)'),0,k,k)); % compute m of each cluster
last = label;
%[v,label] = max(bsxfun(@minus,m'*X,dot(m,m,1)'/2),[],1); % assign samples to the nearest centers
[v,label] = max((m'*X - repmat(dot(m, m,1)', [1 n])/2),[],1); % assign samples to the nearest centers
end
[u,v,label] = unique(label);

I execute the code, but it has some error as following:
Error using ~=
Matrix dimensions must agree.

Error in litekmeans (line 16)
end

Error in WaveletBasedImageSegmentation (line 226)
u =litekmeans(mm',2);u=u(:); id1=find(u==1);c1=sum(mm(id1))/length(id1); id2=find(u==2); c2=sum(mm(id2))/length(id2);[c3 c4]=min([c1 c2]); idx2=find(u==c4);

Please fix it for me.
Thanks,

Error using ~=
Matrix dimensions must agree.

Error in litekmeans (line 16)
end

Error in WaveletBasedImageSegmentation (line 226)
u =litekmeans(mm',2);u=u(:); id1=find(u==1);c1=sum(mm(id1))/length(id1); id2=find(u==2); c2=sum(mm(id2))/length(id2);[c3 c4]=min([c1 c2]); idx2=find(u==c4);

hui cheng

pixval is removed in newer version of MATLAB. For newer version of MATLAB, impixelinfo can be used. Also you may comment as ' %pixval on'.

Sir i have this error.

Undefined function 'pixval' for input arguments of type 'char'.

Error in WaveletBasedImageSegmentation (line 100)
figure, imshow((M));title(' M');pixval on;

This bimodal segmentation method provides least segmentation error and can be compared with other noise robust state of the art methods such as level set based active contours, noise robust or kernel weighted fuzzy c means.

This method will also give better results in comparison with other algorithms.
The methods can be compared with traditional as well as new methods (but they are also less noise robust) such as clustering methods (based on k-means, fuzzy c means etc.), level set methods (e.g.- fast and robust level set based on fuzzy clustering and LBM etc.), graph based methods (graph cut etc.) and region split & merging based methods (watershed based etc.).

Updates

2.7.0.0

comments corrected.

2.6.0.0

Link to (lite) kmeans has been modified, so link is updated in program and description.

2.5.0.0

only description on main page updated.

2.4.0.0

comments & supplementary file updated

2.3.0.0

Comments/description updated.

2.2.0.0

The line 349 is slightly modified to work on newer version of MATLAB. Credit goes to Justin Du.

2.1.0.0

comments and discription corrected.

2.0.0.0

screenshot changed.

1.9.0.0

comments corrected.

1.8.0.0

The extra results are added.

1.7.0.0

The code for separation of overlapping spots in case of 2d gel images is added.

1.6.0.0

Default parameter's values and comments updated for testing on blob images as well as natural images of public database

1.5.0.0

Default parameter 's values with comments updated to test with blob images as well as natural images in public database.

1.4.0.0

comments in the code are provided for using MATLAB inbuilt k-means implementation instead of 'litekmeans'.

1.3.0.0

comments in code are corrected.

1.2.0.0

Description updated.

1.1.0.0

Description updated.

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Acknowledgements

Inspired by: Toolbox Wavelets, Kmeans Clustering