My matlab code is below
rgb1 = imread(name);
rgb=imresize(rgb1,[512 512]);
I = rgb2gray(rgb);
hy = fspecial('prewitt');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
L = watershed(gradmag);
NHOOD=[100;100;101];
se = strel('arbitrary', NHOOD);
Now I set the NHOOD variable into default as in Matlab Help file [100;100;101]. I want to know is this true and can I do that. If any simple ways how can i set to this variable. Please suggest me ...! Thanks

2 件のコメント

Image Analyst
Image Analyst 2014 年 12 月 26 日
There is an imgradient() function you know, as well as imgradientxy(). You don't have to calculate the gradient yourself manually.
kyawt kyawt
kyawt kyawt 2014 年 12 月 26 日
Yes sir, how can I set this NHOOD variable depend on input image. I think default value is not suitable. I have not imgradient() function, could you give me this code. You tell me, I should use an image' gradient as input to NHOOD variable? Please help me sir because my seminar is next week.
clear all
clc
[filename, pathname] = uigetfile({'*.*'},'Browse');
name=[pathname,filename];
rgb = imread(name);
%%%%Preprocessing Step
I = rgb2gray(rgb);
hy = fspecial('prewitt');
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
NHOOD=[1 0 0; 1 0 0; 1 0 1];
se = strel('arbitrary', NHOOD);
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));%opening-closing-by-reconstruction
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
I2 = I;
I2(fgm) = 255;
%clean the edges of the marker blobs
se2 = strel(ones(1,1));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3,20);
I3 = I;
I3(fgm4) = 255;
%Compute Background Markers
bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
%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);
I4 = I;
I4(imdilate(L == 0, ones(4,4)) | bgm | fgm4) = 255;
figure, imshow(I4);

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2014 年 12 月 25 日

0 投票

The ‘NHOOD’ variable is a matrix, not a vector. You need to put spaces or commas (or both) between the numbers:
NHOOD=[1, 0, 0; 1, 0, 0; 1, 0, 1];

2 件のコメント

kyawt kyawt
kyawt kyawt 2014 年 12 月 26 日
Thank you sir ...!
Star Strider
Star Strider 2014 年 12 月 26 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAudio Plugin Creation and Hosting についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by