Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

morpholgy operation problem

16 views
Skip to first unread message

far8

unread,
Aug 6, 2009, 12:30:21 PM8/6/09
to
hi..
first of all, im just new in matlab software. my question is how to create a function as same as (for example) imdilate? there are three more imerode,imopen and imclose. thus, not allowed to use any function in Image Processing Toolbox except for imread and imshow functions and not copy or rename any of the morphological functions available in Matlab. someone please help me.tq

ImageAnalyst

unread,
Aug 6, 2009, 1:21:11 PM8/6/09
to
On Aug 6, 12:30 pm, "far8 " <far8a...@yahoo.com> wrote:
> hi..
> first of all, im just new in matlab software. my question is how to create a function as same as (for example) imdilate? there are three more imerode,imopen and imclose. thus, not allowed to use any function in Image Processing Toolbox except for imread and imshow functions and not copy or rename any of the morphological functions available in Matlab. someone please help me.tq

---------------------------------------------------------------------------------
imdilate is a local maximum operation. imerode is a local min.
imopen is imerode followed by imdilate. imclose is imdilate followed
by imerode.
Have a next of 4 for loops. Basic process:
halfWindow = windowSize/2;
for col = 1:lastColumn
for row = 1:lastRow
for x=(col-halfWindow ):(col+halfWindow )
for y = (row-halfWindow ):(row+halfWindow )
% Look for max or min in the window centered around (row,
col) using standard techniques.
end
end
end
end
That's basically kind of it. You need to tweak the indexes to make
sure you're not going outside the image, handle edge conditions, and
things like that but I think you get the basic idea. You can also see
if it's faster to have the columns or rows be the outermost loop
(probably it will be the columns since I htink MATLAB goes down rows
in a single column first before moving to the next column). You could
also replace the inner 2 for's with standard indexing and a mean(mean
()) statement if you wanted to.
Good luck,
ImageAnalyst

far8

unread,
Aug 8, 2009, 6:33:02 AM8/8/09
to
imageAnalyst,thank you for your informations and tutorials. its very helpful. but i still dont get the result that i wanted. honestly im very weak in this sofware. can u explain me more about the coding that you gave to me.

ImageAnalyst

unread,
Aug 8, 2009, 7:43:02 AM8/8/09
to
On Aug 8, 6:33 am, "far8 " <far8a...@yahoo.com> wrote:
> imageAnalyst,thank you for your informations and tutorials. its very helpful. but i still dont get the result that i wanted. honestly im very weak in this sofware. can u explain me more about the coding that you gave to me.

---------------------------------------------------------------------------
I'm not sure what you don't understand. Is it that you don't
understand how to get iterate over a 3 by 3 window looking for the
largest value?

Bruno Luong

unread,
Aug 8, 2009, 8:03:03 AM8/8/09
to
"far8 " <far8...@yahoo.com> wrote in message <h5f0et$3ne$1...@fred.mathworks.com>...

> hi..
> first of all, im just new in matlab software. my question is how to create a function as same as (for example) imdilate? there are three more imerode,imopen and imclose. thus, not allowed to use any function in Image Processing Toolbox except for imread and imshow functions and not copy or rename any of the morphological functions available in Matlab. someone please help me.tq

Beside coding from scratch, you can find the the link ready-in-the-cane functions
http://www.mathworks.com/matlabcentral/fileexchange/24705

You need to be able to compile MEX.

Bruno

far8

unread,
Aug 10, 2009, 7:05:05 AM8/10/09
to
i think i got a picture about what im doing...i just need a few examples to study...by the way...i got a problem to generate a graphical from the coding. i want to compare the result between the real function and the coding that i make myself. >>here's the coding for dilation...

IM=imread('paint.bmp');
Image=im2bw(IM);
Se = ones(3,2);
Ap = [2,2];Method=('binary');
Isize=size(Image);
Iout=zeros(size(Image));
tmpSize=size(Se);
for i=1:Isize(1,1)
for j=1:Isize(1,2)
if(Image(i,j)>0)
for m=1:tmpSize(1,1)
for n=1:tmpSize(1,2)
tmp1=i-Ap(1,1)+m;
tmp2=j-Ap(1,2)+n;
if(Se(m,n)>0 & tmp1>0 & tmp2>0 & tmp1<=Isize(1,1) & tmp2<=Isize(1,2))
Iout(tmp1,tmp2)=Iout(tmp1,tmp2)+Se(m,n);
end
end
end
end
end
end
for i=1:Isize(1,1)
for j=1:Isize(1,2)
if(Iout(i,j)>1) Iout(i,j)=1;
end;
end
end

figure,imshow(Image)
figure,imshow(Iout)

>>real function for dilation:

IM=imread('beras.bmp');
Se=ones(3,2);
IMage2=imdilate(IM,Se);
figure,imshow(IM),figure,imshow(IMage2)

can someone help me to generate a plot/graphical between these comparison?

ImageAnalyst

unread,
Aug 10, 2009, 7:46:23 AM8/10/09
to
far8:
That doesn't look right to me. How is the inner part of your loop
finding the maximum? It looks like it may work (I haven't tried it)
for binary images only, but not for gray scale images.

You can subtract the images and then show the difference to compare
them.
Good luck,
ImageAnalyst

far8

unread,
Aug 10, 2009, 12:15:19 PM8/10/09
to
what do you mean by subtract the images and then show the difference to compare
them?

ImageAnalyst

unread,
Aug 10, 2009, 12:37:25 PM8/10/09
to
On Aug 10, 12:15 pm, "far8 " <far8a...@yahoo.com> wrote:
> what do you mean by subtract the images and then show the difference to compare
> them?

--------------------------------------------------------------------------------------------
Use imsubtract() to subtract.
Use imshow() to show the subtracted image in a figure window or axes.

far8

unread,
Aug 10, 2009, 1:54:02 PM8/10/09
to
how i want to make a calibration between these pictures? the result are show in figure only. i think i want to show it in plotting a graph. but how?

ImageAnalyst

unread,
Aug 10, 2009, 2:43:14 PM8/10/09
to
On Aug 10, 1:54 pm, "far8 " <far8a...@yahoo.com> wrote:
> how i want to make a calibration between these pictures? the result are show in figure only. i think i want to show it in plotting a graph. but how?

----------------------------------------------------------------------------------------------------------
What do you mean by calibration? You have the official MATLAB-
supplied way of doing a dilation, and you have your own flavor of it
(to put it nicely). Since you aren't doing it right, they will be
different. Subtracting is one way of showing differences. PSNR is
another. I don't think you really know what you want to do and so I
think you should rethink this a bit. I have no idea what it is that
you think you want to graph (presumably a line-type of plot).

0 new messages