フィルターのクリア

I have one matlab code which gives me totally 3*3 matrix of an put image but very time i run the code the output will be change and big difference between the outputs are coming every time. here following my code pls help me n it

1 回表示 (過去 30 日間)
clc;clear all;close all; %% 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'); conversionform = makecform('srgb2lab'); %the form of the conversion is defined as from rgb to l a b lab_img = applycform(imgkk,conversionform); %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
cl1=segmented_images{1}(:,:,1); cl2=segmented_images{2}(:,:,2); cl3=segmented_images{3}(:,:,3);
cll1=imresize(cl1,[100 100]); cll2=imresize(cl2,[100 100]); cll3=imresize(cl3,[100 100]); data=cll1;
[mk1 mk2]=size(data); G=0; S=0; N=0; for i=1:mk2
if(max(data(:,i))>125);
G=G+1;
end
if(max(data(:,i))>135 && max(data(:,i)<196));
S=S+1;
end
if(max(data(:,i))<196);
N=N+1;
end
end
count_red=[G S N];
dataa=cll2; [mk1 mk2]=size(dataa); G=0; S=0; N=0; for i=1:mk2
if(max(dataa(:,i))>155);
G=G+1;
end
if(max(dataa(:,i))>145 && max(dataa(:,i)<156));
S=S+1;
end
if(max(dataa(:,i))<146);
N=N+1;
end
end
count_black=[G S N];
dataaa=cll3; [mk1 mk2]=size(dataaa); G=0; S=0; N=0; for i=1:mk2
if(max(dataaa(:,i))>155);
G=G+1;
end
if(max(dataaa(:,i))>145 && max(dataaa(:,i)<156));
S=S+1;
end
if(max(dataaa(:,i))<146);
N=N+1;
end
end
count_yellow=[G S N];
%% Count is
disp('Count for red pixels is (In ordr of Granulation Slought and Nacrotics)') count_red
disp('Count for red pixels is (In ordr of Granulation Slought and Nacrotics)') count_black
disp('Count for red pixels is (In ordr of Granulation Slought and Nacrotics)') count_yellow
  3 件のコメント
Vertika Jain
Vertika Jain 2017 年 1 月 18 日
My M.tech research topic is shadow detection and removal for occluded object info in HRSI. I've successfully completed the detection part, but unable to remove the detected shadow.
Can anyone help me with d same.
Jan
Jan 2017 年 1 月 18 日
@Vertika Jain: Please do not post a question in the comment section of anotehr question. Prefer to open a new thread. Thanks.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by