Ask Your Question
0

Problem with brightness changing by pixel-access. Mat.

asked 2018-09-09 11:45:40 -0600

Na_Osi gravatar image

Hello!

I am trying to mix two RGB images with smooth change of brightness in adjacent area.

If i multiply my pixel's value with some integer value(1,2,3...) i see the result.

But if if try to use some coefficient "C"(float) like "C = N/50", there N - number of pixel in area and 50 - lenght of area i don't see result althougnt see some warning 4244 about conversion "float" to "_Tp"

Am i misstake? Please help me to solve this problem.

I am working with images in Mat. depth=8 and nChannels=3

the code is:

for (int i = 0; i < imgRez.rows; i++) {
 for (int j = 0; j < imgRez.cols; j++) {
   for (int n = 0; n < 51; x++) {  
float c = n / 50; 
imgRez.at<Vec3b>(i, j)[0] = imgL.at<Vec3b>(i, j - 1)[0] * (1 - c) + imgR.at<Vec3b>(i,j)[0] * c;
imgRez.at<Vec3b>(i, j)[1] = imgL.at<Vec3b>(i, j - 1)[1] * (1 - c) + imgR.at<Vec3b>(i,j)[1] * c;
imgRez.at<Vec3b>(i, j)[2] = imgL.at<Vec3b>(i, j - 1)[2] * (1 - c) + imgR.at<Vec3b>(i,j)[2] * c;}}}
edit retag flag offensive close merge delete

Comments

yea, don't do this.

noobs always want to use Mat::at, and usually shoot their own foot..

what are you trying to achieve here ? (to avoid the obvious XY problem)

berak gravatar imageberak ( 2018-09-09 11:48:22 -0600 )edit
1

why the j-1 sillyness ?

sorry to say so, but the for n loop is plain bullshit.

berak gravatar imageberak ( 2018-09-09 11:49:51 -0600 )edit

Thank you for help!

"what are you trying to achieve here ? (to avoid the obvious XY problem)" I am trying to unite two images for get panorama. The only way i see - to create new image and fill it by pixels of two source images.

"why the j-1 sillyness ?" Yeah. seems like mistake.

"sorry to say so, but the for n loop is plain bullshit." Yeah. it does not work correct.

Na_Osi gravatar imageNa_Osi ( 2018-09-09 12:21:20 -0600 )edit

" with smooth change of brightness in adjacent area." <-- maybe you need to explain this better !

berak gravatar imageberak ( 2018-09-09 12:35:31 -0600 )edit
1

"maybe you need to explain this better !"

two images of my panorama has area(space,place,zone), there last 25 pixels of left img = first 25 pixels of right img. i want to make smooth(gradual,slow) change of brightness in this area from left to right img. Clear?

Na_Osi gravatar imageNa_Osi ( 2018-09-09 12:41:55 -0600 )edit

are you aware, that there's a "stiching" module for this ?

berak gravatar imageberak ( 2018-09-09 12:44:42 -0600 )edit

"are you aware, that there's a "stiching" module for this ?" i heard about this. but did not use. Thank you for ideas

Na_Osi gravatar imageNa_Osi ( 2018-09-09 13:12:07 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2018-09-09 11:50:53 -0600

berak gravatar image

updated 2018-09-09 12:36:06 -0600

if you want to blend 2 images, please use addWeighted() instead of writing for loops.

edit flag offensive delete link more
0

answered 2018-10-23 15:53:06 -0600

Na_Osi gravatar image

Hello! I am sorry, but did not answer early. Correct code in this case:

float c = (float)(n / 50);
for (int i = 0; i < imgRez.rows; i++) 
for (int j = 0; j < imgRez.cols; j++)
for (int k = 0; k < imgRez.channels(); k++)
pano.at<Vec3b>(i, j)[k] = leftImg.at<Vec3b>(i, j)[k] * (1 - c) + rightImg.at<Vec3b>(i, j - leftOrigArea)[k] * c;

I think, it s problem with coefficient "c" datatype. if i use transform to "(float)", code works.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-09-09 11:45:40 -0600

Seen: 169 times

Last updated: Oct 23 '18