<div dir="ltr"><div><div><div>Dear all,<br><br></div>please have a look at following code.<br><br></div>The aim is to adjust the intensitivity levels of an image to new values...something like imadjust in Matlab.<br><br></div><div>I did not find something like this in IPD or in SIVP, therefore the try.<br></div><div><br></div>For my purposes it's enough, though not all image types are maybe supported...<br><div><br></div><div>But the code did work with a bmp and jpg-file.<br></div><div><br><br><pre style="font-family:Monospaced;font-style:normal"><span style="color:rgb(176,24,19)">function</span> <span style="color:rgb(131,67,16);font-weight:bold">out</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(0,0,0);text-decoration:underline">AdjustImage</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(131,67,16);font-weight:bold">In_low</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(131,67,16);font-weight:bold">In_high</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(131,67,16);font-weight:bold">Out_low</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(131,67,16);font-weight:bold">Out_high</span><span style="color:rgb(74,85,219)">)</span>

    <span style="color:rgb(100,174,100);font-style:italic">//make sure we work with doubles</span>
    <span style="color:rgb(131,67,16);font-weight:bold">img</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">double</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>

    <span style="color:rgb(160,32,240)">select</span> <span style="color:rgb(174,92,176);text-decoration:underline">ndims</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">)</span>
    <span style="color:rgb(160,32,240)">case</span> <span style="color:rgb(188,143,143)">2</span> <span style="color:rgb(100,174,100);font-style:italic">// 2D array (GrayScaleImage)</span>
        <span style="color:rgb(100,174,100);font-style:italic">//normalize image</span>
        <span style="color:rgb(0,0,0)">MIN</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">min</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
        <span style="color:rgb(0,0,0)">MAX</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">max</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
        <span style="color:rgb(131,67,16);font-weight:bold">img</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(92,92,92)">-</span><span style="color:rgb(0,0,0)">MIN</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">./</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">MAX</span><span style="color:rgb(92,92,92)">-</span><span style="color:rgb(0,0,0)">MIN</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
        <span style="color:rgb(100,174,100);font-style:italic">//make sure img is in the range [In_low;In_high]</span>
        <span style="color:rgb(131,67,16);font-weight:bold">img</span> <span style="color:rgb(92,92,92)">=</span>  <span style="color:rgb(50,185,185)">max</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">In_low</span><span style="color:rgb(0,0,0)">,</span> <span style="color:rgb(50,185,185)">min</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">In_high</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
        <span style="color:rgb(131,67,16);font-weight:bold">out</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">(</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span> <span style="color:rgb(92,92,92)">-</span> <span style="color:rgb(131,67,16);font-weight:bold">In_low</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">./</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">In_high</span> <span style="color:rgb(92,92,92)">-</span> <span style="color:rgb(131,67,16);font-weight:bold">In_low</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(0,0,0)">;</span>
        <span style="color:rgb(131,67,16);font-weight:bold">out</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(131,67,16);font-weight:bold">out</span> <span style="color:rgb(92,92,92)">.*</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">Out_high</span> <span style="color:rgb(92,92,92)">-</span> <span style="color:rgb(131,67,16);font-weight:bold">Out_low</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">+</span> <span style="color:rgb(131,67,16);font-weight:bold">Out_low</span><span style="color:rgb(0,0,0)">;</span>
    <span style="color:rgb(160,32,240)">case</span> <span style="color:rgb(188,143,143)">3</span> <span style="color:rgb(100,174,100);font-style:italic">// hypermat (ColorImage)</span>
        <span style="color:rgb(160,32,240)">for</span> <span style="color:rgb(0,0,0)">i</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(188,143,143)">3</span>
            <span style="color:rgb(100,174,100);font-style:italic">//normalize image</span>
            <span style="color:rgb(0,0,0)">MIN</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">min</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
            <span style="color:rgb(0,0,0)">MAX</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">max</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
            <span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">-</span><span style="color:rgb(0,0,0)">MIN</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">./</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">MAX</span><span style="color:rgb(92,92,92)">-</span><span style="color:rgb(0,0,0)">MIN</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
            <span style="color:rgb(100,174,100);font-style:italic">//make sure img is in the range [In_low;In_high]</span>
            <span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">=</span>  <span style="color:rgb(50,185,185)">max</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">In_low</span><span style="color:rgb(0,0,0)">,</span> <span style="color:rgb(50,185,185)">min</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">In_high</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
            <span style="color:rgb(131,67,16);font-weight:bold">out</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">img</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">-</span> <span style="color:rgb(131,67,16);font-weight:bold">In_low</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">./</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">In_high</span> <span style="color:rgb(92,92,92)">-</span> <span style="color:rgb(131,67,16);font-weight:bold">In_low</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(0,0,0)">;</span>
            <span style="color:rgb(131,67,16);font-weight:bold">out</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(131,67,16);font-weight:bold">out</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">.*</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">Out_high</span> <span style="color:rgb(92,92,92)">-</span> <span style="color:rgb(131,67,16);font-weight:bold">Out_low</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">+</span> <span style="color:rgb(131,67,16);font-weight:bold">Out_low</span><span style="color:rgb(0,0,0)">;</span>
        <span style="color:rgb(160,32,240)">end</span>
    <span style="color:rgb(160,32,240)">end</span>
<span style="color:rgb(176,24,19)">endfunction</span><span style="color:rgb(0,0,0)">;<br><br><br></span></pre><pre style="font-family:Monospaced;font-style:normal"><span style="color:rgb(0,0,0)">/<span style="font-family:arial,helvetica,sans-serif">/test case 2D<br></span></span></pre><pre style="font-style:normal"><span style="font-family:arial,helvetica,sans-serif"><span style="color:rgb(0,0,0)">img = rand(240,320);<br>adj_im</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(0,0,0)">AdjustImage</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">img</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">0.2</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">0.8</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">0</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;<br><br><font size="2"><br></font></span><font size="2"><br><span style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">//test case hypermat<br></span><span style="color:rgb(0,0,0)"><br>img(:,:,1) = rand(240,320);<br></span></span><span style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">img(:,:,2) = rand(240,320);</span></span><br><span style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)"><span style="color:rgb(0,0,0)">img(:,:,3) = rand(240,320);</span></span><br></span><span style="color:rgb(0,0,0)">adj_im</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(0,0,0)">AdjustImage</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">img</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">0.2</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">0.8</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">0</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span><br></span></font></span></pre><pre style="font-style:normal"><span style="font-family:arial,helvetica,sans-serif"><font size="2"><span style="color:rgb(0,0,0)"></span></font></span></pre><pre style="font-style:normal"><span style="font-family:arial,helvetica,sans-serif"><font size="2"><span style="color:rgb(0,0,0)">For those who have IPD installed, you can use ShowImage() or ShowColorImage() to see the results.<br><br>For those who don't at least the 2D case should be possible to visualize with Matplot()...the hypermat case...don't know.<br></span></font></span></pre><pre style="font-style:normal"><br><span style="font-family:arial,helvetica,sans-serif"><font size="2"><span style="color:rgb(0,0,0)"><span style="font-family:arial,helvetica,sans-serif"><font size="2"><span style="color:rgb(0,0,0)">f = figure();<br></span></font></span><span style="font-family:arial,helvetica,sans-serif"><font size="2"><span style="color:rgb(0,0,0)">f.color_map = graycolormap(255);<br></span></font></span><span style="font-family:arial,helvetica,sans-serif"><font size="2"><span style="color:rgb(0,0,0)">Matplot(img);</span></font></span><br><br><br><br></span></font></span></pre><pre style="font-family:Monospaced;font-style:normal"><span style="font-family:arial,helvetica,sans-serif"><font size="2"><span style="color:rgb(0,0,0)">BR,</span></font></span><span style="color:rgb(0,0,0)"><span style="font-family:arial,helvetica,sans-serif"><font size="2"><br>Philipp</font></span><br></span></pre><pre style="font-family:Monospaced;font-style:normal"><span style="color:rgb(74,85,219)"></span></pre><pre style="font-family:Monospaced;font-style:normal"><span style="color:rgb(0,0,0)"><br><br><br></span></pre><br><br><br><br><br><br clear="all"><div><div><div><div><br>-- <br><div class="gmail_signature">There we have the salad.</div>
</div></div></div></div></div></div>