use evalfis to read input under a range

Hi,
May i know is there any coding can can be use for evalfis to read input under range or not? For my case:
A=imread('Linggi.tif');
[m n p]=size(A)
r=A(:,:,1);
g=A(:,:,2);
b=A(:,:,3);
Y=readfis('mam.fis');
for i = 1:m,
for j = 1:n,
k=r(i,j) > 88 & r(i,j) <= 90;
l=g(i,j) > 134 & g(i,j) <= 140;
z=b(i,j) > 144 & b(i,j) <= 145;
k1=double(k);
l1=double(l);
z1=double(z);
evalfis([k1 l1 z1],Y)
end
end
I find out that the output for all the row and column read are the same, which means the inference system did not run for the input.
Is that got another method of evalfis can be use for me to use to read input that contains range?

6 个评论

Hi,
May I know is that the value under evalfis([ eg },Y), for the eg part, is that necessary for me to put number? Can i put range?
Thanks.
Hi. I don't understand what you want to do but:
Output = zeros(size(r));
for i = 1:m,
for j = 1:n,
k=r(i,j) > 88 & r(i,j) <= 90;
l=g(i,j) > 134 & g(i,j) <= 140;
z=b(i,j) > 144 & b(i,j) <= 145;
k1=double(k);
l1=double(l);
z1=double(z);
Output(i,j) = evalfis([k1 l1 z1],Y);
end
end
% or
k= r > 88 & r <= 90;
l= g > 134 & g <= 140;
z= b > 144 & b <= 145;
k1=double(k);
l1=double(l);
z1=double(z);
Output = evalfis([k1(:) l1(:) z1(:)],Y);
Output = reshape(Output,[m n]);
Hi,
Actually what i want to do is to let the inference system automatic justify the output classes based on the input range such as k, l and z. The coding is worked out, however, the output answer for all the output it run appears the same answer. Therefore, I want want to ask, for my case, is that the problem of output value are all the same is because of my inference system built wrong already?
Thanks.
Why your inputs are logical or zero and one? Check your fuzzy system in Rule Viewer:
Y = readfis('mam.fis');
ruleview(Y)
you can enter your inputs in the lower left of the rule viewer window in the input box then press enter:
[0 0 0]
[0 1 0]
[0 0 1]
Hi,
I put the input as k1(:) l1(:) z1(:). Is that i cannot use that as input although I already declare the value of input by range in k1,l1 and z1 form? I have try to put input through and the output value can be show out. I have input [88 134 144] and it successfully show out the value. If like that, why when using ruleview the output can be show out but when i run the coding the output value only shows out the same value as when i open ruleviewer? Is that mean my input did not pass through the rule that i have been built up?
Thanks.

请先登录,再进行评论。

 采纳的回答

In your code, input isn't same as [88 134 144]. They are logical (0,1):
evalfis([88 134 144])
but:
evalfis([0 1 1])
Maybe, this is what you want:
clear;
A=imread('Linggi.tif');
[m n p]=size(A);
r=A(:,:,1);
g=A(:,:,2);
b=A(:,:,3);
Y=readfis('mam.fis');
Mask = r > 88 & r <= 90 & g > 134 & g <= 140 & b > 144 & b <= 145;
k1=r(Mask);
l1=g(Mask);
z1=b(Mask);
Output = evalfis([k1 l1 z1],Y);
Result = A;
Result(Mask) = Output;

19 个评论

Hi,
I have try out the coding but it shows out error of ??? Error using ==> evalfismex The first input must be a defined DOUBLE matrix
Error in ==> evalfis at 84
[output,IRR,ORR,ARR] = evalfismex(input, fis, numofpoints);
Error in ==> test at 11
Output = evalfis([k1 l1 z1],Y);
Is that I need to convert k1 l1 and z1 to double?
Thanks.
clear;
A1=imread('Linggi.tif');
A = double(A1);
[m n p]=size(A);
r=A(:,:,1);
g=A(:,:,2);
b=A(:,:,3);
Y=readfis('mam.fis');
Mask = r > 88 & r <= 90 & g > 134 & g <= 140 & b > 144 & b <= 145;
k1=r(Mask);
l1=g(Mask);
z1=b(Mask);
Output = evalfis([k1 l1 z1],Y);
Result = A1;
Result(Mask) = Output;
Hi,
Thanks, the coding is work. By the way, is there any coding that I can use to know which value of k1,l1 and z1 that the inference system selected to evaluate the output?
Thanks
[row col]=find(Mask);
%%%or
[k1 l1 z1 Output]
Hi,
Thanks, I now can find out the input value and the output value already. Really helps a lot. I use [k1 l1 z1 Output] to display out the input and output value. Actually I have another question. For now, the value of input and output can be show out already, can I know is there any coding that can be use to show out the image of the based on the different value of output that the inference system evaluate?
Thanks.
I don't understand, can you explain more?
Hi,
What I mean is, now the value of k1,l1 and z1 together with output are display out already. However, can I find back the location of the pixel which have the 3 input value that selected by inference system, and show out the output by color regarding to different type of classes that I set? For example, my output value is from 0.5 to 6.5, i want to put under a set of output range which contain 0.5-1.5 , 1.5-2.5 , 2.5-3.5 , 3.5-4.5 , 4.5-5.5 , 5.5-6.5 . I want to show out the image which contain different color based on different output range and display on the pixel of the image. Like that can understand what I want to ask about ?
clear;
Output = rand(10,10).*6 + 0.5;
imshow(Output,[],'InitialMagnification','fit')
colormap('jet')
Or you can code it like this:
clear;
m = randi([0 4],50,50);
[M,N]=size(m);
n = 1;
C = cell(size(m));
C(m==0) = {cat(3,zeros(n),zeros(n),zeros(n))};
C(m==1) = {cat(3,zeros(n),ones(n),zeros(n))};
C(m==2) = {cat(3,ones(n),ones(n),zeros(n))};
C(m==3) = {cat(3,ones(n),zeros(n),zeros(n))};
C(m>3) = {cat(3,ones(n),ones(n),ones(n))};
img = cell2mat(C);
imshow(img,'InitialMagnification','fit');
% set(gca,'XTick',(1:n:size(img,1))-0.5)
% set(gca,'YTick',(1:n:size(img,2))-0.5)
% set(gca,'XTickLabel','')
% set(gca,'YTickLabel','')
% grid on
% set(gca, 'GridLineStyle', '-');
% axis on
Hi,
I have try to run the coding, I find out that that size of the image has change which becomes bigger already. Is there any way for the image display maintain the original size image?
Thanks.
Output = evalfis([k1 l1 z1],Y);
New_Image = zeros(size(Mask));
New_Image(Mask) = Output;
Hi,
Is this coding applied on the output image? Because actually what I want to do is, based on the output range that undergoes after the inference system, the original image,A1, the pixel is classify out by different color according to different output range that it belongs to. Is there any coding that can be use to do for that part? for example, the pixel that contain output value from 0.5 to 1.5 in image A1 can be display by red color in the new figure image display.
Thanks.
clear;
A1=imread('Linggi.tif');
A = double(A1);
[m n p]=size(A);
r=A(:,:,1);
g=A(:,:,2);
b=A(:,:,3);
Y=readfis('mam.fis');
Mask = r > 88 & r <= 90 & g > 134 & g <= 140 & b > 144 & b <= 145;
k1=r(Mask);
l1=g(Mask);
z1=b(Mask);
Output = evalfis([k1 l1 z1],Y);
im = zeros(size(Mask));
im(Mask) = Output;
[M,N]=size(im);
C = mat2cell(A1,ones(1,M),ones(1,N),3);
C(im>=0.5 & im<1.5) = {uint8(cat(3,255,0,0))};
img = cell2mat(C);
imshow(img,'InitialMagnification','fit');
Hi, May I know what did the coding of C = mat2cell(A1,ones(1,M),ones(1,N),3); and {uint8(cat(3,255,0,0))} refers to? Can you explain me about these two coding? Thanks.
Image A1 converts to cell array C, in each cell of C puts one of the image pixel values (red,green and blue components means each cell is 1x1x3).
{uint8(cat(3,255,0,0))}
Concatenate these three number in third dimension, then convert it to uint8.
Hi,
Ok,I understand the coding already. By referring to your coding, the output range 0.5-1.5 are display as red. I try to add other range C(im>=1.5 & im<2.5) = {uint8(cat(3,255,255,0))}; but the image did not display out for two color, it only appear red color only, is that i still need to edit other part of coding?
Thanks
No, I checked it with some random inputs:
clear;
A1 = uint8(zeros(10,10,3));
Mask = logical(randi([0 1],10,10));
Output = rand(nnz(Mask),1)*6.5;
im = zeros(size(Mask));
im(Mask) = Output;
[M,N]=size(im);
C = mat2cell(A1,ones(1,M),ones(1,N),3);
C(im>=0.5 & im<1.5) = {uint8(cat(3,255,0,0))};
C(im>=1.5 & im<2.5) = {uint8(cat(3,255,255,0))};
C(im>=2.5 & im<3.5) = {uint8(cat(3,255,0,255))};
C(im>=3.5 & im<4.5) = {uint8(cat(3,0,0,255))};
C(im>=4.5 & im<5.5) = {uint8(cat(3,0,255,255))};
C(im>=5.5 & im<6.5) = {uint8(cat(3,0,255,0))};
img = cell2mat(C);
imshow(img,'InitialMagnification','fit');
Hi, May I know why need to use code of A1 = uint8(zeros(10,10,3));? Is that to clear the initial pixel value of the image? What did the code of Mask = logical(randi([0 1],10,10)); and Output = rand(nnz(Mask),1)*6.5; means?
I used these 3 lines for testing the code, you don't need these lines.
A1 = uint8(zeros(10,10,3));
Mask = logical(randi([0 1],10,10));
Output = rand(nnz(Mask),1)*6.5;
Hi, Thanks, the image can display out different color at different output range already. If I want to input other range, mask1=r > 928 & r <= 100 & g > 147 & g <= 150 & b > 134 & b <= 150; and the result use the same output range that set before to display different color for different range, the part of k1=r(Mask); l1=g(Mask); z1=b(Mask); and im(Mask) = Output; how to edit?
Thanks.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by