🎓 First order? Get 25% OFF — use code BISHOPS at checkout  |  💬 Chat on WhatsApp

Design algorithms ( Java)

📅 September 8, 2025 ✍️ Edu Essay ⏱ 2 min read

Question description

Problem 1Please refer the document below A binary digital image a rectangular grid of black and white pixels. The image shown in Figure 1 consistsof 17*9 pixels.Diagram is belowIn this assignment, you write a program to count the connected blocks in a binary digital image. For example:There are three connected blocks in Figure 2a, six connected blocks in Figure 2b, 14 connected blocks inFigure 2c, and one connected block in Figure 2d. If we count white blocks, there are two connected blocksin Figure 1.Create a NetBeans java project, add the jar file “stdlib-package.jar”. The “Picture” class in this packagecan read and show digital image files. You can also get the height, width of the image, and the color of eachpixel on the image. The following code opens a image file, displays it, returns the height and width of theimage, and the color of a pixel at grid position x,y.Picture pic = new Picture(fileName);pic.show();height = pic.height();width = pic.width();5 Color t = pic.get(x, y);In order to find a connected block, you find a black pixel, then you recursively visit all neighbors of the pixelto check if any neighbor is a black pixel too. Then you move to the neighbor, and repeat until no more“black pixel” neighbors. As shown in Figure 3, there are 8 neighbors a pixel.You can use this skeleton code. Function “CountConnectedBlocks” receives a file name and returns thenumber of connected black-colored blocks.import edu.princeton.cs.introcs.Picture;import java.awt.Color;public class ImageBlocks {stat i c Color BLACK = new Color(0,0,0);5 stat i c Color WHITE = new Color(255,255,255);private int height;private int width;int [ ][ ] visited;

Our Key Guarantees

  • 100% Plagiarism-Free
  • On-Time Delivery
  • Student-Friendly Pricing
  • Human-Written Papers
  • Free Revisions (14 days)
  • 24/7 Live Support

Frequently Asked Questions About Our Essay Writing Service