image processing - Applying Laplacian filter in Matlab -
i got 2 errors
non-scalar operator
and
undefined function 'unit8'
here code:
clc clear close image=double('img.tif'); filter=[0 -1 0 ; -1 5 -1 ; 0 -1 0]; [rows,cols] = size(image); outputimage = zeros(rows,cols); row = 2:rows-1 col = 2:col-1 outputimage (row,col)= sum (sum(image(row-1: row+1: col-1: col+1: filter ))); end end %figure,imshow (unit8(image)),title ('originalimage') outputimage =unit8(outputimage); figure,imshow (outputimage, title('enchanceimage'))
solution one
there way compute masking without loops. here code:
clc clear close image=imread('img.tif'); filter=[0 -1 0 ; -1 5 -1 ; 0 -1 0]; [rows,cols] = size(image); outputimage = zeros(rows,cols); filtered_3x3 = imfilter(image,filter,'replicate'); outputimage = im2uint8(filtered_3x3); imshow(outputimage);
first should read images imread
function , imfilter
can apply mask image. im2uint8
can convert image uint8.
solution two
if want change own code, lines need changed. here code:
clc clear close image=imread('img.tif'); filter=[0 -1 0 ; -1 5 -1 ; 0 -1 0]; rows = size(image,1); cols = size(image,2); outputimage = zeros(rows,cols); row = 2:rows-1 col = 2:cols-1 i=1:3 outputimage (row,col,i)= sum (sum(double(image(row-1: row+1, col-1: col+1 , i)) .* filter )); end end end image =uint8(image); figure,imshow (outputimage)
first should read image imread
. size(image)
not give correct dimension, assign them
rows = size(image,1); cols = size(image,2);
. moreover, col = 2:cols-1
not col = 2:col-1
. there syntax error in loops. check it. for i=1:3
can apply mask each rgb
matrix. @ end, uint8
function not unit8
one!
Comments
Post a Comment