OpenCV Mat processing time
Just looking over the two functions, I would probably say the first function is a better practice.  It's shorter (meaning it's more maintainable), it uses fewer variables (which can cause less confusion), and does the same thing as the second function. Overall the advantage is that the first function is just shorter.

In terms of speed/efficiency (if I had to guess), it looks like the first function would also be a bit faster as well (though not by very much at all). To know for sure which one is faster, test the function calls with OpenCV's methods double getTickCount() and double getTickFrequency().

getTickCount gives you the number of clock cycles after a certain event, e.g., after machine is switched on. 

A = getTickCount()  // number of clock cycles from beginning (for example, 100)
getY(image)      // do whatever process you want
B = getTickCount()  // number of clock cycles from beginning (for example, 150)

C = B - A           // number of clock cycles for processing (150-100 = 50)


Now you want to know how many seconds are these clock cycles. For that, you want to know how many seconds a single clock takes, i.e. clock_time_period. If you find that, simply multiply by 50 to get total time taken.

For that, OpenCV gives second function, getTickFrequency(). It gives you frequency, i.e. how many clock cycles per second. You take its reciprocal to get time period of clock.

time_period = 1/frequency.


Now you have time_period of one clock cycle, multiply it with 50 to get total time taken in seconds.