Problem in converting to uint8()

조회 수: 3 (최근 30일)
Jash Shah
Jash Shah 2020년 5월 11일
댓글: Jash Shah 2020년 5월 16일
The function here takes image matrix and creates a 2w+1 X 2w+1 matrix to convolute over it and average the pixel value and hence create a blur image using averaging method.
% Function to blur any image by average method.
function output = blur(img,w)
[row,cols] = size(img);
total = 0;
freq = (2*w + 1)*(2*w + 1);
temp_i = 1;
temp_j = 1;
output = [];
for i = 1:1:row
for j =1:1:cols
total = 0;
for temp_i = i-w:1:i+w
for temp_j = j-w:1:j+w
if(temp_i >=1 & temp_i<=row & temp_j>=1 & temp_j<= cols)
total = total + img(temp_i,temp_j);
freq = freq+1;
end
end
end
output(i,j) = total/freq;
end
end
% output = uint8(output);
end
The output works fine if for the current code, but if I un-comment the line to get uint8 output image, I get incorrect result. To be precise, I get a uniform matrix having same value as all its elements.

채택된 답변

Navya Seelam
Navya Seelam 2020년 5월 14일
편집: Navya Seelam 2020년 5월 14일
uint8 can represent integers from 0 to 255. Make sure that elements are less than or equal to 255 to get the expected results.
  댓글 수: 1
Jash Shah
Jash Shah 2020년 5월 16일
Oh! Okay got my fault. Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by