getting error as " Undefined function 'exp' for input arguments of type 'uint8'." can someone help me resolve this
4 views (last 30 days)
Show older comments
clc;
clear all;
close all;
I = imread('pluginfile_page-0001.jpg');
I = rgb2gray(I);
figure(1)
imshow(I);
I = imresize(I,[256 256]);
sigma = 1;
sig_s=1;
sig_r=1;
halfwid = sigma * 3;
halfwid = 1;
[xx, yy] = meshgrid(-halfwid:halfwid, -halfwid:halfwid);
Gg=1/16*[1 2 1;2 4 2; 1 2 1];
%Gg = exp(-(xx .^ 2 + yy .^ 2) / (2 * sigma ^ 2));
[M,N]=size(I);
modifyI=uint8((zeros(size(I)+2)));
%COPY THE ORIGINAL IMAGE MATRIX TO THE PADDED MATRIX
for x=1:size(I,1)
for y=1:size(I,2)
modifyI(x+1,y+1)=I(x,y);
end
end
figure(2);
imshow(modifyI);
%LET THE WINDOW BE AN ARRAY
%STORE THE 3-by-3 NEIGHBOUR VALUES IN THE ARRAY
%SORT AND FIND THE MIDDLE ELEMENT
Gf_num1=0;
Gf_den1=0;
Igy=uint8(conv2(modifyI,Gg,'same'));
figure(4);
imshow(Igy);
for i= 2:size(modifyI,1)-1
for j=2:size(modifyI,2)-1
for x=-1:1
for y=-1:1
%window(inc)=modifyI(i+x-1,j+y-1)
Gr = exp(-(abs(Igy(i+x,j+y)-modifyI(i,j)))^2/2*sig_r^2);
%Gr = exp(-((abs((Igy(i+x,j+y)-modifyI(i,j)))^2)/2*sig_r^2));
Gs=exp(-(((i+x)-i)^2+((j+y)-j)^2)/2*sig_s^2);
Gf_num = Gs*Gr*Igy(i+x,j+y);
Gf_num1=Gf_num1+Gf_num;
Gf_den=Gs*Gr;
Gf_den1 = Gf_den+Gf_den1;
end
end
Gfg(i-1,j-1) = Gf_num1 / Gf_den1;
end
end
%Gfg1 =im2uint8(Gfg);
% Gfg=uint8(Gfg);
figure(3);
imshow(Gfg);
0 Comments
Accepted Answer
Image Analyst
on 21 Jan 2020
If it doesn't like uint8, then cast it to double
I = double(rgb2gray(I));
0 Comments
More Answers (0)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!