How to merge regions from region adjacencies graph.
3 views (last 30 days)
Show older comments
kyawt kyawt
on 16 Dec 2014
Commented: kyawt kyawt
on 24 Dec 2014
I have the following code and I want to merge regions by using mean color or average intensity value etc.
clear all
clc
[filename, pathname] = uigetfile({'*.*'},'Browse');
name=[pathname,filename];
rgb = imread(name);
figure,imshow(rgb);
%%%%Preprocessing Step
I = rgb2gray(rgb);
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
L = watershed(gradmag);
figure,imshow(L); %gradient img
Lrgb = label2rgb(L);
%Mark the Foreground Objects
se = strel('disk',1);
Io = imopen(I, se);%opening
Ie = imerode(I, se);
Iobr = imreconstruct(Ie, I); %opening-by-reconstruction
Iobrd = imdilate(Iobr, se);%closing-by-reconstruction
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);%calculate regional maxima to obtain foreground markers
I2 = I; %superimpose
I2(fgm) = 255;
%clean the edges of the marker blobs
se2 = strel(ones(1,1)); %ones(5,5)
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3,60);
I3 = I;
I3(fgm4) = 255;
figure, imshow(I3)
title('Modified regional maxima superimposed on original image (fgm4)');
%Compute Background Markers
bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
figure, imshow(bw), title('Thresholded opening-closing by reconstruction (bw)');
%too close to the edges of the object
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
%Compute the Watershed Transform of the Segmentation Function
gradmag2 = imimposemin(gradmag, bgm | fgm4);
L = watershed(gradmag2);
figure, imshow(L);
imtool(L)
I4 = I;
I4(imdilate(L == 0, ones(4,4)) | bgm | fgm4) = 255;
imtool(I4);
figure, imshow(I4);
[n e] = imRAG(L);
hold on;
for i=1:size(e, 1)
plot(n(e(i,:), 1), n(e(i,:), 2), 'linewidth', 2, 'color', 'black');
end
plot(n(:,1), n(:,2), 'bo');
By using this code, I can get the following region adjacencies graph. Now I want to merge these oversegmented regions. How can i continue this coding to merge similar regions. Please help me ...!
The size of the image is 732x486 outdoor scene RGB image. How to merge similar regions ...
0 Comments
Accepted Answer
Image Analyst
on 16 Dec 2014
Maybe you want to use this algorithm instead: http://www.mathworks.com/matlabcentral/fileexchange/37197-dem--diffused-expectation-maximisation-for-image-segmentation
3 Comments
Image Analyst
on 22 Dec 2014
Sorry but I haven't actually tried the code. I suggest you contact the author.
More Answers (0)
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!