Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: GLCM texture image
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Lee ZY

Posts: 25
Registered: 9/1/10
GLCM texture image
Posted: Jan 16, 2013 10:25 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I would like to generate a texture image based on GLCM Inverse Difference Moment. After going through this site 'http://www.fp.ucalgary.ca/mhallbey/texture_calculations.htm'. If I am not wrong, it's found that we need to create a sliding window and generate the texture value(s) on each window, which then form a texture image. and below shows the code i did, which i am not sure if i'm doing it right. Could you guys please advise me on this?

image=imread('circuit.tif');
[imageHeight, imageWidth]=size(image);
windowWidth = 3;
windowHeight = 3;
k2=floor(windowWidth/2);

for i = 1:imageHeight - windowHeight + 1
for j = 1:imageWidth - windowWidth + 1

% Compute the normalized GLCM in each window as illustrated in 'http://www.fp.ucalgary.ca/mhallbey/ans_ex_1.htm

window = image(i:i + windowHeight - 1, j:j + windowWidth - 1, :);
wind=window(:);
Num=length(unique(wind));

glcm1 = graycomatrix(window,'NumLevels',Num,'G',[]) ;
glcm2=glcm1';
symm=glcm1+glcm2;
sumEle=sum(symm(:));
M=symm/sumEle ; %normalization

% operations within window
for a=1:Num
for b=1:Num
IDM(a,b) = M(a,b)/(1+(a-b)^2) ; % Inverse Difference Moment
end
end

IDM = sum(IDM(:));

% replace IDM to the center of the window and save it as image2
image2(i+1,j+1)=IDM ;

end
end
[x,y]=size(image2);
CroppedInverseDiffImage=image2(2:x,2:y); % crop the vacant pixels
figure(2),imshow(CroppedInverseDiffImage);


The result does not look 'good', wondering if there's any mistake i made. Thank you very much in advance.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.