;
0026 <span class="keyword">end</span>
0027 
0028 <span class="keyword">if</span> ndims(img)&lt;2 || ndims(img)&gt;3
0029     error(<span class="string">'Works only for grayscale or color images'</span>);
0030 <span class="keyword">end</span>
0031 
0032 <span class="keyword">if</span> ndims(img)==3 &amp;&amp; size(img,3)&lt;4
0033     <span class="comment">% RVB image</span>
0034     newimg = zeros(p1,q1, size(img,3));
0035     <span class="keyword">for</span> m=1:size(img,3)
0036         newimg(:,:,m) = <