![]() |
Mean filter algorithm C++
hi, i read up some articles about mean filter and its use-age. however im connfused about it when it comes to coding it. can someone explain to me in mathematical term on how its done? this is what i implemented so far, help from here one will be great:
Code:
void |
Re: Mean filter algorithm C++
How much stack space have you got?
Code:
unsigned int meanarray[262144];int is 4 bytes so this allocates 1MB of stack space. |
Re: Mean filter algorithm C++
so can i declare as 'long' instead? im not too sure about malloc..
|
Re: Mean filter algorithm C++
No, because long is also 4 bytes. If you don't want to use malloc (why not?) then you need to read your compiler documentation to find out how to increase the stack size.
malloc'd arrays are just as easy to use as stack arrays. Here's a stack example: Code:
int arr[32];Code:
int *arr=(int*)malloc(32*sizeof(int)); |
Re: Mean filter algorithm C++
ok thanks
what is this for in your reply? : arr[1]=27; |
Re: Mean filter algorithm C++
It's an example of how to use it. It sets the 2nd element of arr to 27. As you can see, there is no difference between the stack version and the heap version.
|
Re: Mean filter algorithm C++
i would like to add one more point, though its not really necessary , it will still work without this Check, but its adviced to have these checks.
int *p=(int*)malloc(32*sizeof(int)); if(NULL != p) //Check to see proper allocation of memory ....Do your Stuff.... else{ //Not enough memory } |
Re: Mean filter algorithm C++
okay it settled the stack overflow problem. so coming back to the MAIN issue.
looking at this codeline: Code:
|
Re: Mean filter algorithm C++
The previous point about checking the return value of malloc is absolutely correct. Much of programming is about handling error conditions properly.
What are the values in image[0]..image[4], and exactly what result in meanarray[0] are you expecting to see? Have you tried checking the algorithm in a simple testbed, e.g. Code:
main()I would expect meanarray[0] to contain 4, in this case (2+4+8+1+9=24; 24/5=4). |
Re: Mean filter algorithm C++
Hi thanks for replying. I managed to have the mean values now. AQctually i solved the stack overflow issue by doing 2 things: first i changed my variable to meanarray1[] instead and i declare this into the global definition way up in this whole programme.
I now want to do median filter. I am unsure how to sort the arrays out from increasing order. Can u give me some hints on how to go about? |
| All times are GMT +5.5. The time now is 03:02. |