필터 지우기
필터 지우기

how to apply mask on image

조회 수: 9 (최근 30일)
Isee You
Isee You 2012년 2월 12일
댓글: Image Analyst 2019년 8월 14일
I am making mask of one's and I want this mask to walk on the image to get the average of the Pixels under the mask.and complete to the full image size. mask size[3,3] image size [400,400]

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 2월 12일

Image Analyst
Image Analyst 2012년 2월 12일
Try convolution:
filteredImage = conv2(grayImage, ones(3)/9);
You can do the same thing with imfilter().
  댓글 수: 2
Thulitha Theekshana
Thulitha Theekshana 2019년 8월 14일
Remember to convert the output of conv2 to uint range. ( maybe using a function such as mat2gray ) before imshow. Otherwise the image wouldn't be displayed.
Image Analyst
Image Analyst 2019년 8월 14일
In my code, grayImage needs to be a single or double. If it's a uint8 you will need to cast to double or single before passing in to conv2():
filteredImage = conv2(double(grayImage), ones(3)/9);
Then filteredImage will be a single or double. To display it without casting back to uint8, you can use [] in imshow(), like this:
imshow(filteredImage, []); % Brackets needed if the floating point image is not in the range 0 to 1.
or you can just cast it back to uint8:
filteredImage = uint8(conv2(double(grayImage), ones(3)/9));
imshow(filteredImage); % Brackets not needed if it's uint8

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

Community Treasure Hunt

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

Start Hunting!

Translated by