use evalfis to read input under a range
3 次查看(过去 30 天)
显示 更早的评论
leow
2013-8-9
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 个评论
leow
2013-8-10
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.
Iman Ansari
2013-8-10
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
2013-8-10
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
2013-8-10
编辑:Iman Ansari
2013-8-10
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
2013-8-10
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.
采纳的回答
Iman Ansari
2013-8-10
编辑:Iman Ansari
2013-8-10
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 个评论
leow
2013-8-10
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
2013-8-10
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;
leow
2013-8-10
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
leow
2013-8-10
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.
leow
2013-8-10
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
2013-8-10
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
leow
2013-8-11
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.
Iman Ansari
2013-8-11
Output = evalfis([k1 l1 z1],Y);
New_Image = zeros(size(Mask));
New_Image(Mask) = Output;
leow
2013-8-11
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
2013-8-11
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');
leow
2013-8-11
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.
Iman Ansari
2013-8-11
编辑:Iman Ansari
2013-8-11
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
2013-8-11
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
2013-8-11
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
2013-8-11
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
2013-8-11
编辑:Iman Ansari
2013-8-11
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
2013-8-11
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)