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');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by