Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: function output
Replies: 1   Last Post: Jun 9, 2011 1:54 AM

 Messages: [ Previous | Next ]
 Forrest Posts: 19 Registered: 8/25/08
function output
Posted: Jun 8, 2011 10:28 AM

Hello, I need some help with a little project. I must split a program into dedicated functions for each task. There are two functions. The first function converts the RGB image into BW. The second function should allow the selection of a point with the mouse on the BW image returned by function 1, and output the point's coordinates. I haven't had any success yet.

Here is the code:

>function mediere(I)
>% I este o imagine
>global BW;
>gray=rgb2gray(I);
>figure, imshow(gray), title('imaginea obtinuta dupa rgb2gray');
>AVG = medfilt2(gray, [5 5]); %se calculeaza o medie cu pixelii vecini
>figure, imshow(AVG), title('imaginea obtinuta dupa medfilt2');
>BW=im2bw(AVG, graythresh(AVG));
>figure, imshow(BW), title('imaginea obtinuta dupa graythresh');
>end

>function [] = coordonate(k)
>% k - input image
>% draw circle on image
>% coordonate(image);
>figure;
>imshow(k);
>pt = ginput(1)
>r = 15 ;
>x1 = pt(1,1);
>y1 = pt(1,2);
> x2 = x1;
> y2 = y1 + r;
> xpt = [x1 x2];
> ypt = [y1 y2];

>for i=1:size(k,1)
> for j=1:size(k,2)
> x2 = j;
> y2 = i;
> val = floor(sqrt((x2-x1)^2 + (y2-y1)^2));
> if(val == floor(r))
> nim(i,j,1) = 255;
> nim(i,j,2) = 0;
> nim(i,j,3) = 0;
> else
> nim(i,j,1) = k(i,j,1);
> nim(i,j,2) = k(i,j,2);
> nim(i,j,3) = k(i,j,3);
> end
> end
>end

>uint8(nim);
>figure;
>imshow(nim);
>%line(x,y);
>line(xpt,ypt);
>end

This is the main:
>close all