File Exchange

image thumbnail

image segmentation based on Markov Random Fields

version 1.0.0.0 (3.98 KB) by lin
I have written codes for image segmentation based on Markov Random Fields.

19 Downloads

Updated 02 Nov 2011

View License

The file includes two parts,main_seg and 7 functions. Test image maybe any image of Matlab.

Cite As

lin (2020). image segmentation based on Markov Random Fields (https://www.mathworks.com/matlabcentral/fileexchange/33592-image-segmentation-based-on-markov-random-fields), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (33)

yunsen li

this code is great, thanks lot. an if add some note, it will be better

Example doesn't work, but easy fixes are given in the comments.

XN = cat(3,Xu1,Xu,Xur,Xr,Xdr,Xd,Xd1,X1);
2.if it is show the blank image
in the function main_seg.m
in the end add one line
imshow(seg,[]);

Is the solution!!! thank a Zhao

Can someone explain what energyofeaturefield and energyoflabelfield funcions doing here?

Natsu dragon

begginer01

Sir...i want my output image as gray image not color how to modify this code..kindly suggest me..plz..

begginer01

Great job!!!! but i am facing problem at: Error:
for i=1:class_number
E(:,i)=sum(Nei8~=1,8);
end
Subscripted assignment dimension mismatch.
this is of EnergyOfFeatureField

Himanshu Sharma

Nei8=imstack2vectors(NeiX(segmentation));
this line sowing error
please help me with a solution

tenzin nangchung

There should be some description about what part of code does what..
Can anyone help?

tenzin nangchung

After adding the changes to the code as mentioned in the comments i am getting only a blank all-white image.

alok singh

Maria Kanwal

is class-number in main_seg.m presents number of clusters? so it is pre-defined?

Hysen

The comments help me a lot, and the results are good. As to the description about the code, I recommend you read a book named "基于Markov随机场的小波域图像建模及分割——Matlab环境",it's written in Chinese.

John

Zero comments in code. Example code does not work. No reference given for algorithm definition.

The results are satisfactory. But there is no function headers and no description available.

Dali Yang

Even resolved the error, the output is far from good.

zhao

1.if the erro is NeiX
in the function NeiX.m
XN=NeiX(X)
before end
add one line command
XN = cat(3,Xu1,Xu,Xur,Xr,Xdr,Xd,Xd1,X1);
2.if it is show the blank image
in the function main_seg.m
in the end add one line
imshow(seg,[]);

Haitham AlMubarak

when I run the programme I have this message?
Undefined function 'ICM' for input arguments of type 'uint8'.why????

robber john

segment result fair

Black Mamba

Solution found to the blank image, add these lines to the main_seg.m

figure;
imshow(seg,[]);

Black Mamba

The output is a white blank window / image? Does it work for only a particular kind of image.

I fed grayscale 320*480 image.png s to it

salam amer

Error in ==> EnergyOfLabelField at 4
Nei8=imstack2vectors(NeiX(segmentation));
i am try to solve the error but all my try is failed
please help me

Tushar

I am trying to execute this code, but the end output that I am getting is blank(white) image. Any idea what I am missing.

Krawels

Thanks a lot for this code. I hate matlab coding and u done great job here :)
ps. Yunjin Chen comment helps with error.

Krawels

Yunjin Chen

the basic solution is

in the function XN=NeiX(X)
before end
add one line command
XN = cat(3,Xu1,Xu,Xur,Xr,Xdr,Xd,Xd1,X1);

Wasim

???Undefined function or method 'ICM' for input arguments of type 'double'.
segmentation=ICM(image,class_number,potential,maxIter) Please help to solve this

ECE

Hossein

Hi there
How can I understand this code and run it?

Sk Massich

the output of NeiX, XN is not assigned.

Neix Function is supposed to assign the potential of a click being well classified depending on its neighbors.

Xu, Xur, Xr, Xdr, Xd Xd1 and X1 store the neighbors labels. Although there's NO comment at all which makes things unlikely to be properly solved,a possible solution is adding a potential function such as the ratio of coincident neighbors with the central pixel.

XN=sum(cat(3,Xu1==X,Xu==X,Xur==X,Xr==X,Xdr==X,Xd==X,Xd1==X,X1==X),3)/8;

However the result obtained is far from what I was expecting.

Tai Fei

Yunjin Chen

Error in ==> NeiX at 2
[s,t,K]=size(X);

??? Output argument "XN" (and maybe others) not assigned during call to "C:\Users\chen\Documents\MATLAB\Markov
segmentation\NeiX.m>NeiX".

Error in ==> EnergyOfLabelField at 4
Nei8=imstack2vectors(NeiX(segmentation));

Error in ==> ICM at 11
E1=EnergyOfLabelField(segmentation,potential,width,height,class_number);

Error in ==> main_seg at 9
seg=ICM(I,class_number,potential,maxIter);

Yunjin Chen

what's the matter?

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

Community Treasure Hunt

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

Start Hunting!