I am trying to segment the image into 3 layers Mask, FG and BG. I have attached my code and please help me......

2 views (last 30 days)
I tried to segment image into Mask, FG and BG but i am not getting correct output. Mak layer must contain Text part of image ( Mask will be in binary form), FG contains image or graphs and BG contains color of text. How can i do this. My code is i=imread('20.jpg'); grayImage=rgb2gray(i); % Get the dimensions of the image. numberOfColorBands should be = 1. [rows columns numberOfColorBands] = size(grayImage); % Integer image. imageToThreshold = grayImage; startingLowThreshold = 100; startingHighThreshold = 250; % Let's compute and display the histogram. [pixelCount grayLevels] = imhist(grayImage); subplot(2, 3, 2); bar(pixelCount); title('Histogram of Original Image'); xlim([0 grayLevels(end)]); % Scale x axis manually. grid on; binaryImage = (imageToThreshold > startingLowThreshold) & (imageToThreshold < startingHighThreshold);
subplot(2,2,2); imshow(binaryImage, []); axis off; title('Mask of the image'); subplot(2,2,1);imshow(i); title('Input Image');% original image
set(gcf, 'Position', get(0,'Screensize'));
drawnow; % Force display to update immediately.
% Let's process this to get the background, which will be the smooth areas.
filteredImage = entropyfilt(grayImage, ones(15));
binaryImage = filteredImage > 4;
binaryImage = imfill(binaryImage, 'holes');
% Fill in the textured areas with local background
% to get an estimate of what the background
% would be without the objects in there.
BackgroundImage = roifill(grayImage, binaryImage);
subplot(2, 2, 3);
imshow(BackgroundImage, []); % Display image.
title('Foregroung Image');
binar = filteredImage < 5;
ForegroundImage = roifill(grayImage, binar);
subplot(2, 2, 4);
imshow(ForegroundImage, []); % Display image.
title('Background Image');

Answers (0)

Community Treasure Hunt

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

Start Hunting!