Skip to content

This is a project that employs Java GUI and database connection programming. Its purpose is to solve a programming problem, more in Readme.

Notifications You must be signed in to change notification settings

nvatuan/Center-of-attention-source

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Center of Attention Application

This is a Java Application that will solve for the given image's center pixels. The actual problem and information about the app will be described below.

The problem

Original Problem Description

Read original description
For this project, we're given an image in which some object of interest (e.g. a face, or a license plate, or an aircraft) appears as a large block of contiguous pixels all of the same colour. (Probably some image-processing has already occurred to achieve this, but we needn't worry about that.) We want to find the centre of the object in the image.

We'll do this by finding which pixels of the given colour have maximum depth. The depth of a pixel P is the minimum number of steps (up, down, left, or right) you have to take from P to reach either a pixel of a different colour or the edge of the image.


pixel depths pic

In the picture, the red pixel marked ""3"" has a depth of 3: it takes at least 3 steps from there to reach something other than another red pixel. Note that the steps need not be all in the same direction. Only one red pixel has depth 3: the one right in the middle of the red region. Similarly, the blue pixel marked ""2"" has a depth of 2 (but it is not the only one with this depth). The green and purple pixels all have depth 1.

The pixels of a given colour with the largest depth will be found at the centre of the biggest solid region(s) of that colour. Those are the ones we want.

The function you'll write (central_pixels) belongs to the following data structure:

struct Image
{
 unsigned *pixels;
 unsigned width, height;

 vector<unsigned> central_pixels(unsigned colour) const;
 // other functions ...
};

The image data consists of a one-dimensional array pixels of unsigned integers (or just integers, in languages that don't have unsigned integers as such), which correspond to pixels in row-by-row order. (That is, the top row of pixels comes first, from left to right, then the second row, and so on, with the pixel in the bottom right corner last of all.) The values of the pixels array elements represent colours via some one-to-one mapping whose details need not concern us.

The central_pixels function should find and return all the positions (pixels array indices) of the pixels having the greatest depth among all pixels of colour colour).

Note 1. The final test in the suite (Big_Test) is a 16-megapixel image (4 megapixels in the Python version), so you will need to consider the time and space requirements of your solution for images up to that size.

Note 2. The data in an Image object should not be assumed to be constant after instantiation. The test suite frequently modifies images and then re-tests them.

Problem summary

More formally, given a two-dimension matrix A[][] contains only integers. Define "max_depth of a pixel" as d(x, y), is the shortest Manhattan distance from tile [x][y] to:

  • Either, another tile [u][v] so that A[x][y] ≠ A[u][v], (in other words, different colored pixels)
  • Or either, just right outside the border of A[][]

Given an integer k. Find all tiles [x][y] so that d(x,y) is the greatest among all A[x][y] equals k.

The Application

The application is written purely in Java, and make use of Java's extensive framework/library, namely the following:

  • Swing, AWT
  • JDBC for MySQL

User Interface

Consists of 3 area:

  • The leftmost is called "Functions". Contains mostly buttons that will do what they are meant to do (based on the text on the button)
  • The rightmost is called "Input/Output". This is where the program will read in the data, and output back results.
  • The middle part is called "Canvas". This is where our program will render an image based on what the user has inputted. Colors are randomly picked so that no different numbers has the same colors.

Save/Load

The current version of the application supports Save/Load via a MySQL Database. Just hit the "Dữ liệu Database" (Database Data) button on the left to see the screen for the option.

To use this feature, you will need to configurate your MySQL database as described in the Installation section. The database control panel has 3 options:

  • Clone Input (of the selected row)
  • Delete (the selected row)
  • Save Current (Input to database) The current version does not include Save/Load via files. (Again, Sorry! Using a DBMS is an overkill, but it is a requirement)

Installation

  • First, download the repository.
  • If you are planning to use the Save/Load feature, next step is to install MySQL. You can skip this step if you don't need to use it.
    1. Make sure MySQL is running on default port 3306, with user root and password root (I know it's bad but this is hardcoded. Sorry!)
    2. Create the database:
      • Recover the database by using the dump.sql or,
      • Create a database and table for storing with the following statements:
      CREATE DATABASE javabase;
      USE javabase;
      CREATE TABLE tb (id INT PRIMARY KEY AUTO_INCREMENT, serial BLOB, created DATETIME);
  • Then, if you are on Windows, you can run build-run.bat to automatically build the project then run it. Afterward, you only need to run run.bat.
  • If you are on Linux or Mac, you will have to write your bash version of the script.

Screenshots

When you just launch the program

image

Read about the Problem

image

Help ([?] Button)

  • Help on INPUT section: Description and Example image
  • Help on OUTPUT section: Description and Example image

Execute (Thực thi)

  • A small test to demonstrate image rendering image

  • A slightly bigger test image

  • A medium-sized test (200x200) image image

Large test (around 1000x1000) makes Java's BufferedImage uses up huge memory and long allocate time so unfortunately there will be no images for larger testcases.

Database Access (Dữ liệu Database)

image

About

This is a project that employs Java GUI and database connection programming. Its purpose is to solve a programming problem, more in Readme.

Resources

Stars

Watchers

Forks

Packages

No packages published