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');
2 个评论
Image Analyst
2014-5-5
I fixed your code formatting for you this time, but I'd like you to see this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup so you can do it yourself next time.
回答(1 个)
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
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 Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!