필터 지우기
필터 지우기

Help Please Looking for error in this code...I tried for 6 hours...but i am failed to find an error.

조회 수: 1 (최근 30일)
This is code....Thresholding function is working correctly...but after thresholding i applied Morphological opening and closing of which result is not displayed. code is.
%filtim1 is input grayscale image.
imageforT = filtim1;
image_thresholded = uint8(zeros(size(imageforT)));
image_thresholded(imageforT >1) =255;
subplot(3,2,4);
imshow(image_thresholded,[]);
title('thresholded image');
st=strel('square',11);
MorphoOpen=imopen(image_thresholded,st);
MorphoClose=imclose(MorphoOpen,st);
subplot(3,2,5);
imshow(MorphoClose,[]);
title('Morphological Close');
%======================
ImageFilled = imfill(MorphoClose,'holes');
subplot(3,2,6);
imshow(ImageFilled,[]);
title('Fill Image');

답변 (1개)

Image Analyst
Image Analyst 2014년 5월 6일
This line here:
image_thresholded(imageforT > 1) = 255;
sets every non-zero pixel to 255. So what it looks like depends on how many pixels in your input image are exactly zero. For me, and the cameraman standard demo image, it gave a completely white image, because there are no zero pixels. By not attaching your image, you've delayed any response that I might have given now. Do you consider anything more than 1 the foreground? Please attach your image so we can finish this.
  댓글 수: 1
Image Analyst
Image Analyst 2014년 5월 6일
By the way, it does work if you use a different image and change the thresholding method and value:
%filtim1 is input grayscale image.
filtim1 = imread('saturn.png');
if ndims(filtim1) >= 3
filtim1 = rgb2gray(filtim1);
end
subplot(3,2,1);
imshow(filtim1,[]);
title('Original image');
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(filtim1);
subplot(3, 2, 2);
bar(grayLevels, pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
imageforT = filtim1;
image_thresholded = imageforT > 50;
subplot(3,2,4);
imshow(image_thresholded,[]);
title('thresholded image');
st=strel('square',11);
MorphoOpen=imopen(image_thresholded,st);
MorphoClose=imclose(MorphoOpen,st);
subplot(3,2,5);
imshow(MorphoClose,[]);
title('Morphological Close');
%======================
ImageFilled = imfill(MorphoClose,'holes');
subplot(3,2,6);
imshow(ImageFilled,[]);
title('Fill Image');

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

Community Treasure Hunt

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

Start Hunting!

Translated by