how to threshold image in 3*3 window?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/750174/image.png)
and for imthresh function it returns this error :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/750179/image.png)
0 Commenti
Risposte (1)
Image Analyst
il 26 Set 2021
Modificato: Image Analyst
il 26 Set 2021
Try beginning at row and columns 2,
for p= (k+1) : row-k
for q = (k+1) : col-k
2 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!