You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
use evalfis to read input under a range
6 views (last 30 days)
Show older comments
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 Comments
Iman Ansari
on 9 Aug 2013
Iman Ansari
on 10 Aug 2013
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]);
leow
on 10 Aug 2013
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.
Iman Ansari
on 10 Aug 2013
Edited: Iman Ansari
on 10 Aug 2013
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]
leow
on 10 Aug 2013
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.
Accepted Answer
Iman Ansari
on 10 Aug 2013
Edited: Iman Ansari
on 10 Aug 2013
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 Comments
leow
on 10 Aug 2013
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.
Iman Ansari
on 10 Aug 2013
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;
Iman Ansari
on 10 Aug 2013
[row col]=find(Mask);
%%%or
[k1 l1 z1 Output]
leow
on 10 Aug 2013
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.
Iman Ansari
on 10 Aug 2013
I don't understand, can you explain more?
leow
on 10 Aug 2013
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 ?
Iman Ansari
on 10 Aug 2013
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
Iman Ansari
on 11 Aug 2013
Output = evalfis([k1 l1 z1],Y);
New_Image = zeros(size(Mask));
New_Image(Mask) = Output;
leow
on 11 Aug 2013
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.
Iman Ansari
on 11 Aug 2013
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');
Iman Ansari
on 11 Aug 2013
Edited: Iman Ansari
on 11 Aug 2013
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.
leow
on 11 Aug 2013
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
Iman Ansari
on 11 Aug 2013
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');
leow
on 11 Aug 2013
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?
Iman Ansari
on 11 Aug 2013
Edited: Iman Ansari
on 11 Aug 2013
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;
leow
on 11 Aug 2013
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.
More Answers (0)
See Also
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)