The for loop on classification gives every time different value?

3 visualizzazioni (ultimi 30 giorni)
I have one code which gives me 3*3 matrix value of classification in image .but when I run this code 2nd time it will change the output value every time. I got something new 3*3 matrix value can any one help me in this.I already submitted my report on this previously generated results now the problem is I have submission on that this values gina differ so please anyone help me in this
  2 Commenti
Image Analyst
Image Analyst il 30 Giu 2016
How can we do that unless we can run your code to reproduce what you observed? We can't even begin to fix it. Read this link then fix your post.
riddhi desai
riddhi desai il 30 Giu 2016
Modificato: Walter Roberson il 1 Lug 2016
for p = 1:10
Selection of Original Image %%%%%
[a,b]=uigetfile('*.jpg','Select the Input Image');
str=strcat(b,a);
f=imread(str);
% f=imread('1.jpg');
%%%%%% Color Space Transformation %%%%%%
%%%% Separation of Hue, Saturation and Intensity Components %%%%%
fhsv=rgb2hsv(f);
fh=fhsv(:,:,1);
%figure,imshow(fh);title('The Hue Component of the Original Image');
fs=fhsv(:,:,2);
%figure,imshow(fs);title('The Saturation Component of the Original Image');
fv=fhsv(:,:,3);
%figure,imshow(fv);title('The Intensity Component of the Original Image');
% figure,imshow(fv);title('Intensity Component');
fgr=rgb2gray(f); %%Conversion of original Image to grayscale Image
figure,imshow(fgr);title('Original Grayscale Image');
Diffusion for Effective Filtering %%%%%%%
%%%%%%%%% Diffusion Parameters %%%%%%%%%%
iter =10;
delta_t = 1/7;
kappa = 15;
adi=double(fs);
diff_im = adi;
dx = 1;dy = 1;dd=sqrt(2);
hN = [0 1 0; 0 -1 0; 0 0 0];
hS = [0 0 0; 0 -1 0; 0 1 0];
hE = [0 0 0; 0 -1 1; 0 0 0];
hW = [0 0 0; 1 -1 0; 0 0 0];
hNE = [0 0 1; 0 -1 0; 0 0 0];
hSE = [0 0 0; 0 -1 0; 0 0 1];
hSW = [0 0 0; 0 -1 0; 1 0 0];
hNW = [1 0 0; 0 -1 0; 0 0 0];
for t = 1:iter
nablaN = imfilter(diff_im,hN,'conv');
nablaS = imfilter(diff_im,hS,'conv');
nablaW = imfilter(diff_im,hW,'conv');
nablaE = imfilter(diff_im,hE,'conv');
nablaNE = imfilter(diff_im,hNE,'conv');
nablaSE = imfilter(diff_im,hSE,'conv');
nablaSW = imfilter(diff_im,hSW,'conv');
nablaNW = imfilter(diff_im,hNW,'conv');
cN = 1./(1 + (nablaN/kappa).^2);
cS = 1./(1 + (nablaS/kappa).^2);
cW = 1./(1 + (nablaW/kappa).^2);
cE = 1./(1 + (nablaE/kappa).^2);
cNE = 1./(1 + (nablaNE/kappa).^2);
cSE = 1./(1 + (nablaSE/kappa).^2);
cSW = 1./(1 + (nablaSW/kappa).^2);
cNW = 1./(1 + (nablaNW/kappa).^2);
end
diff_im = diff_im+delta_t*((1/(dy^2))*cN.*nablaN + (1/(dy^2))*cS.*nablaS + ...
(1/(dx^2))*cW.*nablaW + (1/(dx^2))*cE.*nablaE + ...
(1/(dd^2))*cNE.*nablaNE + (1/(dd^2))*cSE.*nablaSE + ...
(1/(dd^2))*cSW.*nablaSW + (1/(dd^2))*cNW.*nablaNW );
% end
f3=diff_im;
Gabor Filtering %%%
%%%%%%%%%%%% Defining Parameters of Gabor Filter %%%%%%%%%%%%%
u=5;
v=8;
m=39;
n=39;d1=39;d2=39;
gaborArray = cell(u,v);
fmax = 10;
gama = sqrt(2);
eta = sqrt(2);
%%%%%%% Application of Gabor Filter %%%%%%%%%
for i = 1:u
fu = fmax/((sqrt(2))^(i-1));
alpha = fu/gama;
beta = fu/eta;
for j = 1:v
tetav = ((j-1)/v)*pi;
gFilter = zeros(m,n);
for x = 1:m
for y = 1:n
xprime = (x-((m+1)/2))*cos(tetav)+(y-((n+1)/2))*sin(tetav);
yprime = -(x-((m+1)/2))*sin(tetav)+(y-((n+1)/2))*cos(tetav);
gFilter(x,y) = (fu^2/(pi*gama*eta))*exp(-((alpha^2)*(xprime^2)+(beta^2)*(yprime^2)))*exp(1i*2*pi*fu*xprime);
end
end
gaborArray{i,j} = gFilter;
end
end
img=double(f3);
[u,v] = size(gaborArray);
gaborResult = cell(u,v);
for i = 1:u
for j = 1:v
gaborResult{i,j} = imfilter(img, gaborArray{i,j});
end
end
featureVector = [];
for i = 1:u
for j = 1:v
gaborAbs = abs(gaborResult{i,j});
gaborAbs = downsample(gaborAbs,d1);
gaborAbs = downsample(gaborAbs.',d2);
gaborAbs = gaborAbs(:);
gaborAbs = (gaborAbs-mean(gaborAbs))/std(gaborAbs,1);
featureVector = [featureVector; gaborAbs];
end
end
figure;imshow(abs(gaborResult{i,j}),[]);title('Result-1');
rimg1=abs(gaborResult{2,5});
rimg2=abs(gaborResult{3,5});
rimg3=abs(gaborResult{4,5});
rimg4=abs(gaborResult{5,5});
figure,subplot(121);imshow(fgr);title('Original Grayscale Image');
subplot(122);imshow(abs(gaborResult{2,5}),[]);title('Result at [Scale Orientation]=[2 5]');
figure,subplot(121);imshow(fgr);title('Original Grayscale Image');
subplot(122);imshow(abs(gaborResult{3,5}),[]);title('Result at [Scale Orientation]=[3 5]');
figure,subplot(121);imshow(fgr);title('Original Grayscale Image');
subplot(122);imshow(abs(gaborResult{4,5}),[]);title('Result at [Scale Orientation]=[4 5]');
figure,subplot(121);imshow(fgr);title('Original Grayscale Image');
subplot(122);imshow(abs(gaborResult{5,5}),[]);title('Result at [Scale Orientation]=[5 5]');
fs1=im2bw(fs);
figure,imshow(fs1);title('Binarized Image');
se2=strel('disk',3);
fs2=imclose(fs1,se2);title('Filling of Small Holes');
figure,imshow(fs2);
se1=strel('disk',5);title('Removal of small regions');
fs3=imopen(fs2,se1);
%figure,imshow(fs3);title('Final Processed Image');
for i=1:size(fs,1)
for j=1:size(fs,2)
if(fs3(i,j)==1)
fs4(i,j)=fs(i,j);
fk1(i,j)=fh(i,j);
fk2(i,j)=fv(i,j);
else
fs4(i,j)=0;
fk1(i,j)=0;
fk2(i,j)=0;
end
end
end
figure,imshow(fs4);title('Extracted Region');
Labelling and Connected Component Analysis %%%%%
[B,L]=bwboundaries(fs3,'noholes');
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'y', 'LineWidth', 4)
end
fk3=cat(3,fk1,fs4,fk2);
fk4=hsv2rgb(fk3);
figure,imshow(fk4);title('Extracted Region as in Original Color Image');
%%%%% Computation of color Features %%%%
seg_mean=mean2(fs4);
disp('The mean of the segmented Region is');
disp(seg_mean);
seg_sd=std2(fs4);
disp('The standard deviation for the segmented Region is');
disp(seg_sd);
I = im2double(fs4);
kurt=kurtosis(I(:));
seg_kurt=kurt;
disp('The kurtosis value for the segmented region is');
disp(seg_kurt);
I2 = im2double(fs4);
seg_skew=skewness(I2(:));
disp('The skewness value for the segmented region is');
disp(seg_skew);
v = var(fs4);
seg_v=mean(v);
disp('The variance value for the segmented region is');
disp(seg_v);
%%%%% Computation of Textural Features %%%%
M=calc_entropy(fs4);
disp('The entropy value for the segmented region is');
disp(M);
%%LBP%%
imwrite(fk4,'ni.jpg');
imgk=imread('ni.jpg');
img=rgb2gray(imgk);
nFiltSize=7;
nFiltRadius=1;
filtR=generateRadialFilterLBP(nFiltSize, nFiltRadius);
effLBP= efficientLBP(img, 'filtR', filtR, 'isRotInv', false, 'isChanWiseRot', false);
binsRange=(1:2^nFiltSize)-1;
figure;
subplot(1, 2, 1)
imshow(imgk);
title('Original segmented image', 'fontSize', 18);
subplot(1, 2, 2)
imshow( effLBP );
title('Efficeint LBP image', 'fontSize', 18);
imwrite(fk3,'nimg.jpg');
imgkk=imread('nimg.jpg');
%figure, imshow(img), title('X axis rock cut'); %figure is for creating a figure window.
% text(size(img,2),size(img,1)+15,...
% 'Unconventional shale x axis cut', ...
% 'FontSize',7,'HorizontalAlignment','right');
cform = makecform('srgb2lab'); %the form of the conversion is defined as from rgb to l a b
lab_img = applycform(imgkk,cform); %converting the rgb image to l a b image using the conversion form defined above.
ab = double(lab_img(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
%figure, imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = imgkk;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
imwrite(segmented_images{k},'nii.jpg');
imgkl=imread('nii.jpg');
cl1=imgkl(:,:,1);
cl2=imgkl(:,:,2);
cl3=imgkl(:,:,3);
[mk1 mk2]=size(cl1);
G=0;
S=0;
N=0;
for i=1:mk2
if(max(cl1(:,i))>100);
G=G+1;
end
if(max(cl1(:,i))>135 && max(cl1(:,i)<196));
S=S+1;
end
if(max(cl1(:,i))<196);
N=N+1;
end
end
count_red=[G S N];
g1(p)=G;
s1(p)=S;
n1(p)=N;
[mk11 mk21]=size(cl2);
G11=0;
S11=0;
N11=0;
for i=1:mk21
if(max(cl2(:,i))>100);
G11=G11+1;
end
if(max(cl2(:,i))>135 && max(cl2(:,i)<196));
S11=S11+1;
end
if(max(cl2(:,i))<196);
N11=N11+1;
end
end
count_black=[G11 S11 N11];
g11(p)=G11;
s11(p)=S11;
n11(p)=N11;
[mk111 mk211]=size(cl3);
G111=0;
S111=0;
N111=0;
for i=1:mk211
if(max(cl3(:,i))>100);
G111=G111+1;
end
if(max(cl3(:,i))>135 && max(cl3(:,i)<196));
S111=S111+1;
end
if(max(cl3(:,i))<196);
N111=N111+1;
end
end
count_yellow=[G111 S111 N111];
g111(p)=G111;
s111(p)=S111;
n111(p)=N111;
%%Count is
count_red1 = [g1(1) s1(1) n1(1)];
count_black1 = [g11(1) s11(1) n11(1)];
count_yellow1 = [g111(1) s111(1) n111(1)];
disp('Count for red pixels is (In ordr of Granulation Slought and Nacrotics)')
count_red1
disp('Count for black pixels is (In ordr of Granulation Slought and Nacrotics)')
count_black1
disp('Count for Yellow pixels is (In ordr of Granulation Slought and Nacrotics)')
count_yellow1
ch = input('Enter your choice either if you want to continew with this image or else go for new image :');
if (ch == 1)
pause(0.1);
end
if (ch==2)
break;
end
end
clc;clear all;close all;
sir this is my code pls help evryyime i get diffrent output

Accedi per commentare.

Risposta accettata

Steven Lord
Steven Lord il 30 Giu 2016
Most likely you're calling some function that uses the random number generator. Reset the generator to a fixed seed at the start of each classification using the rng function and see if that provides reproducibility.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by