Problem proposal - Image cutting

Back to General discussions forum

oezguery     2023-08-06 22:28:41
User avatar

Hi!

I would like to contribute to CodeAbbey with a basic problem idea.

I have an image, (width, height). I want to cut it in a specific aspect ratio (width, height). All integer numbers.

What is the biggest area that can be cut out?

Let's make it a little harder: I have a small display where I show the image. The display has a fixed width. The height is flexible. I resize the image to fit the width of the display and show the image.

Now, I draw a rectangle on the display. The rectangle has the same aspect ratio. (This is usually 16:9 for TV) The aspect ratio must be exact, otherwise TV rejects the uploaded image.

The height or the width of the rectangle is given. What is the area of the corresponding rectangle in the image?

Rodion (admin)     2023-08-08 06:53:30
User avatar

Hi Özgür!

This sounds nice, moreover it is a problem very often haunting those of programmers who work with frontend/UI!

Would you like me to try go on with your idea and shape it out into some specific problem - or perhaps you may have fancy to try creating the problem yourself as a whole?

You'll need to provide two files - one with description (in markdown format, the same used here in forum) and the other with data generation / checking code (Python is supported as a language of choice for it).

Example of the task description in markdown (you can browse any task that way)

Instruction on creating code for task

Regretfully there is no automated way to setup the task itself, so you'll need to send the files by mail (just tell when ready - I'll provide the address and will watch my mailbox carefully).

oezguery     2023-08-08 20:14:35
User avatar

Hi Rodion! the example link is not found for some reason. But it is ok because I know how task descriptions are in this website.

I looked at the instruction for creating the code. The checking code must produce at least two lines:

  1. first line number of test cases.
  2. following line or lines are the test cases, or the input data.

Should also the answers be generated by the checking code? I will write a first iteration for a basic version and you can comment if it fits your expectations.

oezguery     2023-08-08 20:55:41
User avatar

Hi!

I am ready with the first iteration. I basically took the instructions and modified a little bit. If the first iteration is OK, I would like to go on with randomizing the aspect ratio and making it part of the input data.

Rodion (admin)     2023-08-08 21:51:34
User avatar

Ah, sorry, I improperly shortened the link, please retry - should be better!

The checking code must produce at least two lines

rather like this:

  • all lines except the last - is whatever is shown to the user as "input data"
  • the last line - what is expected from user as the answer

it works simply like this - when page is loaded the whole your code is executed, the first part is shown as input, the answer is saved (in "session" variable) - when the user submits the answer, it is compared with the saved line.

if the problem requires some special logic to check the answer (e.g. when multiple answers are possible) - it is also achievable, but probably not needed for your case? feel free to tell - I'll explain better if necessary.

I would like to go on

yep, sure, I tried to set the message for you with my email - it should be shown in yellow below header (also we'll test this feature) - feel free to contact for any specific questions on code etc.

gardengnome     2023-08-12 11:43:01
User avatar

Hi Rodion, I know the problem is still in the test phase but right now the checker expects an unusual end at the end of the output.

Rodion (admin)     2023-08-12 19:11:36
User avatar

Dear Mathias :) yes, this suffix is just for testing, so that proper solution won't make task "solved" if sent inadvertently.

However, since you have already tried this, may we ask for your opinion - how exactly to deal with cutting out the rectangle of requested ratio. There are two options (perhaps more?) - suppose we have 100x100 image and 16:9 ratio. Exact ratio is achieved with rectangle 96x54 i.e. requires cutting both dimensions of image. Alternatively we may prefer to preserve one dimension and cut the other, probably truncating down (100x56). What do you think?

gardengnome     2023-08-12 19:26:31
User avatar

Hi, I am quite okay with the way it is implemented/asked right now where you have to achieve the exact target ratio, i.e. cutting in both dimensions might be necessary.

Rodion (admin)     2023-08-13 06:53:01
User avatar

Ok, thanks! It's author's implementation also, so let it go live, moreover that some people already tried it :)

oezguery     2023-08-14 09:28:38
User avatar

Hi, thank you for trying it.

The aspect ratio must be exact and side lenghts must be integer (no rounding, no half pixels). These are the requirements.

oezguery     2023-08-15 19:56:06
User avatar

I am very happy about having contributed to the CodeAbbey with a task.

kostis_k     2023-10-09 08:16:57
User avatar

I am quite okay with the way it is implemented/asked right now where you have to achieve the exact target ratio, i.e. cutting in both dimensions might be necessary.

Perhaps this fact should be reflected/clearly stated in the problem description in order to avoid confusion. It shouldn't be needed to browse through the forum for a small though necessary detail.

Rodion (admin)     2023-10-09 08:22:19
User avatar

Hi, Konstantine! glad to hear from you - and thanks for suggestion. I remember stumbling over this myself, so now added appropriate note at the bottom of problem statement.

oezguery     2023-10-11 21:25:30
User avatar

This is great, as in the image/television sector the pixels have to be whole numbers, at least in the german public broadcasting.

Please login and solve 5 problems to be able to post at forum