[Scilab-users] adjust image

Philipp Mühlmann p.muehlmann at gmail.com
Tue Feb 23 05:31:13 CET 2016


Dear all,

please have a look at following code.

The aim is to adjust the intensitivity levels of an image to new
values...something like imadjust in Matlab.

I did not find something like this in IPD or in SIVP, therefore the try.

For my purposes it's enough, though not all image types are maybe
supported...

But the code did work with a bmp and jpg-file.


function out=AdjustImage(img, In_low, In_high, Out_low, Out_high)

    //make sure we work with doubles
    img = double(img);

    select ndims(img)
    case 2 // 2D array (GrayScaleImage)
        //normalize image
        MIN = min(img);
        MAX = max(img);
        img = (img-MIN)./ (MAX-MIN);
        //make sure img is in the range [In_low;In_high]
        img =  max(In_low, min(In_high,img));
        out = ( (img - In_low) ./ (In_high - In_low) ) ;
        out = out .* (Out_high - Out_low) + Out_low;
    case 3 // hypermat (ColorImage)
        for i = 1:3
            //normalize image
            MIN = min(img(:,:,i));
            MAX = max(img(:,:,i));
            img(:,:,i) = (img(:,:,i)-MIN)./ (MAX-MIN);
            //make sure img is in the range [In_low;In_high]
            img(:,:,i) =  max(In_low, min(In_high,img(:,:,i)));
            out(:,:,i) = ((img(:,:,i) - In_low) ./ (In_high - In_low)) ;
            out(:,:,i) = out(:,:,i) .* (Out_high - Out_low) + Out_low;
        end
    endendfunction;


//test case 2D

img = rand(240,320);
adj_im = AdjustImage(img,0.2,0.8,0,1);



//test case hypermat

img(:,:,1) = rand(240,320);
img(:,:,2) = rand(240,320);
img(:,:,3) = rand(240,320);
adj_im = AdjustImage(img,0.2,0.8,0,1);

For those who have IPD installed, you can use ShowImage() or
ShowColorImage() to see the results.

For those who don't at least the 2D case should be possible to
visualize with Matplot()...the hypermat case...don't know.


f = figure();
f.color_map = graycolormap(255);
Matplot(img);



BR,
Philipp











-- 
There we have the salad.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160223/995d5b80/attachment.htm>


More information about the users mailing list