run the code and input different values for different operations like graylevel slicing with/without back ground,basic thresholding operation,image negative,contrast stretching.
no worries. What you did is not a mistake after all, it is correct. However, if you are planning on continue working with Matlab in the future you can save yourself a lot of effort by understanding what makes Matlab different from other languages.
Hi Christian Wuerslin
u r absolutely right but i forgot that silly mistake.
thanks again will help me lot in future..
please be aware, that Matlab is not like C or any other compiled language. Matlab is interpreted at run-time and therefore long scripts (or a lot of loops) are very time-consuming. Matlab solves this by supplying powerful matrix operations. Your code
can be simply replaced by
z = (G-1) - y;
What happens is that Matlab automatically detects that y is a matrix of a certain size and returns a a matrix z of the same size. The loops you use are preformed automatically (and way faster). Note that this only works if G is a scalar (in your case) or if G has the same size as y.
The same applies to all loops in your submission. Hope this helps you in future projects.
Updated as a tool box