MATLAB Answers


help with my code

Asked by aboomnea
on 23 Jun 2013

i write this code so i can search for intesity point in 8 direction like this and see also

my code work well but i think it too too too long and take long time 3 minutes can any one help me to make it small and powerful and faster

my code


1 Answer

Answer by Walter Roberson
on 23 Jun 2013
Edited by Walter Roberson
on 23 Jun 2013

You indicate you are searching for intensity points, but you have not defined the algorithm and you have not defined what you want the output to be. The table in the .docx file does not help as you did not give any interpretation of it.

Your existing code has the appearance of a rats nest. There is no point in us analyzing how it works or what it is intended to do, when it would be much easier for you to describe it and document it (including comments.)


on 25 Jun 2013

At first Ignore comments sorry , i forget do delete them .

my code create mask of 3X3 matrix that scan the image

   z=[z1 z2 z3
         z4 z5 z6;
         z7 z8 z9];

and get Average (avgg) and then

   if ( avgg<10 && avgg>300 ||avgg==0 )   

to avoid zero and other values i do not want .

and then i search in 8 direction

c = {@northest, @north, @northwest,@west, @southwest, @south,@southeset,@eset};
                     for f=1:8
                              c{f}(avg,a,x,y,t) ;

for any direction i pass image, avg,x ,y , t (t no of cycle) like this example as you can find in .doc file i write the condition and thin i get the value of northeset

%north eset
function  northest(avg,a,x,y,t) 
while x-1 ~= NaN  && y-1 ~= NaN && x-1 > 0  && y-1>0 


if northeset < 20 && northeset >-20
       if t<50
           dataxnorthest=[dataxnorthest (x-1)];
          dataynorthest=[dataynorthest (y-1)];
         elseif t>=50 && t<100

dataxnorthest ,dataynorthest are the point i find . i divide these storage from (dataxnorthest to dataxnorthest12 ) , to speed i got a lot of data , then at last i combine them at one datax and datay .

   [~,tt]=size (datay);
  [k,m]=size (a);
   z = ones(k,m, 'double');
  z = logical(z);
  for u=1:tt  
        z(datax(u),datay(u)) = 0;

then i use above code to creat array that has same size of image but it array of one and zeroes. expresses the chosen data then


to get the final image

figure;imshow(a, []);title('cancer image')
on 27 Jun 2013

Walter Roberson , help

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!