How can I set the NHOOD variable.

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 Comments

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);

Sign in to comment.

 Accepted Answer

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];

More Answers (0)

Community Treasure Hunt

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

Start Hunting!