How can I define a matlab code for the size of structuring elemtent depends on image size?

2 views (last 30 days)
% here a sample matlab code
SE = strel('disk', R);% I would like to set R depend on image size %Please give me a sample matlab code

Answers (1)

Walter Roberson
Walter Roberson on 3 Jan 2014
sz = min(size(I,1), size(I,2)); %where I is the image
filt_imgs = cell(sz,1);
for R = 1 : sz
SE = strel('disk', R);
filt_imgs{R} = imopen(I, SE);
end
  2 Comments
kyawt kyawt
kyawt kyawt on 6 Jan 2014
Edited: kyawt kyawt on 6 Jan 2014
Please suggest me...! which size of image is suitable for this code. When I used size of image 800*600 my program take long time to run this code. ... clear all clc [filename, pathname] = uigetfile({'*.*'},'Browse'); name=[pathname,filename]; rgb = imread(name); 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); %Mark the Foreground Objects
sz = min(size(I,1), size(I,2)); %where I is the image filt_imgs = cell(sz,1); for R = 1 : sz se = strel('disk', R); filt_imgs{R} = imopen(I, se); end
Ie = imerode(I, se); Iobr = imreconstruct(Ie, I); Ioc = imclose(Io, se); Iobrd = imdilate(Iobr, se); Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr)); Iobrcbr = imcomplement(Iobrcbr); fgm = imregionalmax(Iobrcbr); I2 = I; I2(fgm) = 255; %clean the edges of the marker blobs se2 = strel(ones(5,5)); fgm2 = imclose(fgm, se2); fgm3 = imerode(fgm2, se2); fgm4 = bwareaopen(fgm3,10); %shink them a bit e.g 20 I3 = I; I3(fgm4) = 255; %Compute Background Markers bw = im2bw(Iobrcbr, graythresh(Iobrcbr)); 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); . . .

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!