how to threshold image in 3*3 window?

조회 수: 1 (최근 30일)
majid
majid 2021년 9월 26일
댓글: Image Analyst 2021년 9월 26일
Hello,
I have a 256x256 noisy image and I want to find threshold value of elements on the middle row and column in 3x3 window and then sliding this window all over the image pixel by pixel and do the same.
I do this work by 2 way : graythresh and one file exchange, but I get in both an error! can any one help me to solve this?
here is my code :
clear all;
close all;
clc;
I=im2double(imread ('cameraman.tif'));
size_I=size(I);
%% adding noises%speckle noise
SI=imnoise(I,'speckle',0.2);
% adding salt and pepper noise or shot noise
Shot_noise = imnoise(I, "salt & pepper", 0.10);
% total noise
noisy_image=I+SI+Shot_noise;
subplot(121)
imshow(I);
title('Original Image')
subplot(122)
imshow(noisy_image)
title("noisy image");
%----------------------------------------------------------------
k=1;
hwin=2*k+1;
im= padarray(noisy_image, [k k],'replicate'); % 'zero-padding'
[row,col] = size(im);
% + Mask
plus=zeros(hwin,hwin);
plus(:,2)=1; plus(2,:)=1;
plus_find=find(plus); % plus pixel's positions
for p=1:row-2
for q=1:col-2
w=im(p:p+(hwin-1),q:q+(hwin-1));%sliding window / filter
sw=w(:)'; %sliding window elements
plus_val=w(plus_find)';
center_val=w(5);
% T=graythresh(sw);
% I have error here!
% [~,T]=imthresh(w);
% and also here
% my code is not complete.
end
end
when I use graythresh it returns this error
and for imthresh function it returns this error :

답변 (1개)

Image Analyst
Image Analyst 2021년 9월 26일
편집: Image Analyst 2021년 9월 26일
Try beginning at row and columns 2,
for p= (k+1) : row-k
for q = (k+1) : col-k
  댓글 수: 2
majid
majid 2021년 9월 26일
sorry, same error again.
could you run my codes and the attached function on your system,
I think my system have problem.
Image Analyst
Image Analyst 2021년 9월 26일
OK, I just ran your original code and it ran without any errors.

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by