[Scilab-users] Auto adjust level of a color image

Chin Luh Tan chinluh.tan at bytecode-asia.com
Wed Jun 10 10:16:25 CEST 2020


Hi Mat, 



First of all, thanks Philipp for the example. 



Infact you might be able to get the similar result with Image Arithmetic function - imadd, which will perform the proper int clipping. I attached the file with added lines to compare the results which should be identical.



On the other hand, to adjust the color level or RGB image, you could use "imadjust". 



S2 = imadjust(S) will adjust the image automatically, or define your own source and destination histogram range. 



you could also explore imhistequal for histogram equalisation, however, bear in mind applying these in RGB will caused color distortion. 



On of the way in Color Image processing if you were to adjust to RGB image intensity w/o affecting the color proportion for viewing effect :



1. convert RGB to LAB (rgb2hsv)

2. perform adjustment on the first layer (correspond to "v", in transformed image, the hsv layers are arrange in "v", "s","h")

3. fuse the layers 2 and 3 to the adjusted layer 1

4. convert LAB to RGB



you should get a nicely adjusted color image.



/// sample

S = imread('darkroom.jpg'); 



S2 = rgb2hsv(S);



S3 = imhistequal(S2(:,:,1));



S3(:,:,2:3) = S2(:,:,2:3)



S4=hsv2rgb2(S3);    //hsv2rgb name has been taken by Scilab, so IPCV use hsv2rgb2



imshow(S4);

//




hope this helps.



rgds,

Chin Luh






---- On Wed, 10 Jun 2020 15:40:20 +0800 P M <p.muehlmann at gmail.com> wrote ----



Dear Mat,



not sure if this helps,

but here is a way, how to set brightness using a constant value.



I guess for automatization one can figure out a way using mean pixel value.



Best Regards,

Philipp



img = imread(fullpath(getIPCVpath() + "/images/" + 'baboon.png'));

 // image size = 512 x 512

// result of "imread" is of type 10 --> text object
// (???)..guess: type = unsigned char, which is 8 bit
//
// However this limits the pixel values between 0 and 255
// e.g.: 255 + 1 will be set to "0"
//
// for brightness control we must be able to exceed 255.
// ..we also want to go into negative pixel values
// so we need to change integer type...use int16
// positive pixel values above 255 will be set to 255 afterwards
// negative pixel values will be set to 0 afterwards

nPx = 512*512;

brighnessLv_1 = 128;
brighnessLv_2 = -128;

img_1 = int16(img); 
img_1 = img_1 + brighnessLv_1;
   
img_2 = int16(img);
img_2 = img_2 + brighnessLv_2;

pos = find(img_1 > 255);
img_1(pos) = 255;
pos = find(img_1 < 0);
img_1(pos) = 0;

pos = find(img_2 > 255);
img_2(pos) = 255;
pos = find(img_2 < 0);
img_2(pos) = 0;

img_1 = uint8(img_1);
img_2 = uint8(img_2);

f = figure();
f.figure_size = [1591,610];
f.background = 8;
subplot(1,3,1);
imshow(img);

subplot(1,3,2);
imshow(img_1);

subplot(1,3,3);
imshow(img_2);









Am Di., 9. Juni 2020 um 22:05 Uhr schrieb mat368 <mailto:matthieu.gazon at orange.fr>:




_______________________________________________

users mailing list 

mailto:users at lists.scilab.org 

http://lists.scilab.org/mailman/listinfo/users 


Hello
 I am looking for a function or a code to auto adjust level of color image ?
 I dont see that in thé ipcv package.
 
 Thanks for tour trop.
 Mat
 
 
 
 --
 Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
 _______________________________________________
 users mailing list
 mailto:users at lists.scilab.org
 http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20200610/bec3fe89/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image_arithmetic.sce
Type: application/octet-stream
Size: 1359 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20200610/bec3fe89/attachment.obj>


More information about the users mailing list