Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to carve half of a Thanksgiving Turkey? [closed]

I have a cool problem. I'm trying to highlight exactly 50% of this turkey's mass. In practice it will not be 50%, but if I can get 50%, I can figure the rest out.

My current idea is this: Scan in every pixel to find out the mass of the turkey, in pixels. Then, when I want 50% of the turkey, highlight pixels from left to right until I've highlighted 50% of the pixels.

Does anyone have any better ideas? This is the slowest, brute-force idea that requires looping over every pixel once to count the pixels and again to highlight 50% of them.

Note that dividing the picture vertically would not leave 50% of the turkey, as the turkey's body is a lot meatier than it's neck.

This is a Turkey

like image 992
DanRedux Avatar asked Apr 24 '12 02:04

DanRedux


People also ask

What is it called when you split a turkey in half?

roasted spatchcock turkey on the roasting rack. Credit: Kelly Cline. To "spatchcock" means to remove a bird's backbone so that it will lay flat while cooking. This method (also known as butterflying) ensures even cooking, juicier meat, and a quicker cooking time.


1 Answers

You say the percentage will change, but I'm going to go on a limb here and assume the turkey itself won't.

So you don't need to loop twice. You only need to do it once, map the data into some form of structure that you can reference, then only refer to it each time you need to highlight to figure out how far you need to go.

For instance, make an associative array of <percentage of mass (integer out of a hundred) => vertical column number (int)>

That way, when you need to shade x percent, you only need to loop over cached_data[percent_to_highlight] columns of pixels, shading them all, and then break out of the loop entirely once you reach it.


For even more performance, have two pictures - one fully shaded plus your normal one. The associative array should map percentage => byte_offset

For each image you wish to generate, simply memcpy or whatever PHP's equivalent of a fast, ranged copy from 0 -> byte_offset of the shaded picture over the non-shaded and save. No more looping. You can't get faster than this.

like image 50
Mahmoud Al-Qudsi Avatar answered Oct 06 '22 00:10

Mahmoud Al-Qudsi