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 Kommentare

Image Analyst
Image Analyst am 26 Dez. 2014
There is an imgradient() function you know, as well as imgradientxy(). You don't have to calculate the gradient yourself manually.
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);

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 25 Dez. 2014

0 Stimmen

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 Kommentare

kyawt kyawt
kyawt kyawt am 26 Dez. 2014
Thank you sir ...!
Star Strider
Star Strider am 26 Dez. 2014
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Audio Plugin Creation and Hosting finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by