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

classic Classic list List threaded Threaded
3 messages Options
mat368 mat368
Reply | Threaded
Open this post in threaded view
|

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

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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

Re: Auto adjust level of a color image

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 <[hidden email]>:
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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Tan Chin Luh Tan Chin Luh
Reply | Threaded
Open this post in threaded view
|

Re: Auto adjust level of a color image

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 <[hidden email]> 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 <[hidden email]>:

_______________________________________________
users mailing list
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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

image_arithmetic.sce (1K) Download Attachment