Showing that matter has an atomic nature using Java program

Click For Summary

Discussion Overview

The discussion revolves around the implementation of a Java program for identifying and classifying "blobs" in an image, specifically focusing on the BlobFinder class. Participants are addressing a homework problem that involves understanding the constructor and methods related to blob detection based on pixel classification.

Discussion Character

  • Homework-related
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant expresses confusion about the BlobFinder constructor and the necessary steps to initialize it, referencing advice received about initializing an ArrayList and creating a 2D boolean array.
  • Another participant confirms the need to initialize the ArrayList before adding elements to avoid a NullPointerException.
  • A participant clarifies that the constructor should classify pixels as background or foreground based on a luminance threshold and mentions the definition of a blob as 25 connected foreground pixels.
  • One participant misinterprets the definitions of blobs and beads but later corrects themselves, acknowledging that one blob corresponds to one bead.
  • Questions arise regarding the purpose of the "marked" array in the BlobFinder class and the expected return type of the findBead method, as well as the parameters for this method.
  • Another participant points out that there is no findBead() method in the provided API and emphasizes the need to follow the API for implementing the BlobFinder class.

Areas of Agreement / Disagreement

Participants generally agree on the need to initialize the ArrayList and the definition of a blob. However, there are multiple points of confusion regarding the implementation details, the purpose of certain variables, and the methods that should be included in the BlobFinder class, indicating that the discussion remains unresolved on these aspects.

Contextual Notes

There are limitations in understanding the API provided for the BlobFinder class, including the absence of a findBead method and the unclear role of the marked array. Additionally, there is uncertainty regarding the parameters for the findBead method and how they relate to the blob's center of mass.

s3a
Messages
828
Reaction score
8

Homework Statement


http://pastebin.com/aS3vTR2V

Homework Equations


N/A

The Attempt at a Solution


I'm confused about what I need to do for the BlobFinder constructor. Someone told me that I should “initialize the ArrayList blobs”, then “create a 2D array of booleans called marked, having the same dimensions as picture.” then “enumerate the pixels of picture, and for each pixel (i, j): 1. Create a Blob object called blob., 2. Call findBead() with the right arguments. and 3. Add blob to blobs if it has a non-zero mass.”,

but I'm confused as to why that is what I need to do. Don't I only need to do the following for the BlobFinder contructor?:

Java:
for(int i = 0; i < picture.height(); i++) {

    for(int j = 0; j < picture.width(); j++) {

       Blob blob = new Blob();
       blob.add(i, j);
       blobs.add(blob);
    }
}

I don't even need someone to write Java code for me, but if someone could just explain to me in words and/or pseudocode what I need to do, it would help a lot.

Any help would be greatly appreciated!
 
Last edited by a moderator:
Physics news on Phys.org
With respect to ArrayList objects, yes you need to initialize them before you add something to them

Java:
    ArrayList blobs = new ArrayList();

If you don't do that then you'll get a NullPointerException thrown when you try to execute the blobs.add(blob) in your "for" loop.
 
According to the instructions, the constructor looks like this:

Code:
// find all blobs in the picture using the luminance threshold tau
public BlobFinder(Picture picture, double tau)

So the constructor accepts the picture, and the constant ##\tau##, which is used to classify the pixels as background or foreground. You will classify each pixel as it is read from the picture as background or foreground inside the constructor itself.

You also know a polystyrene bead (a blob) is represented by a disc-like shape, which is composed of 25 connected foreground pixels.

Once you have found 25 connected foreground pixels, you have found a blob. A new field: ArrayList<Blob> blobs, should be used to hold onto the blobs once you've found them.
 
Thanks for the replies.

I thought that a blob was one pixel and a bead was 25+ blobs, but I misread the instructions; 1 blob = 1 bead.

I'm currently confused as to what the purpose of the array pointed to by the variable named "marked" (in the BlobFinder class) is for.

Should the findBead method (in the BlobFinder class) have a return type of Blob?

Also, are the int i and int j parameters of the findBead method (in the BlobFinder class) supposed to be the horizontal and vertical coordinates of the center of mass of a Blob, or can it be any point and not have to be a center of mass?
 
Thanks for the replies.

I thought that a blob was one pixel and a bead was 25+ blobs, but I misread the instructions; 1 blob = 1 bead.

I'm currently confused as to what the purpose of the array pointed to by the marked variable is for.

Should the findBead method (in the BlobFinder class) have a return type of Blob?

There is no findBead() method.

If you tried to understand the instructions more carefully, you would see you were given an API for the BlobFinder class:

Code:
Next, write a data type BlobFinder that has the following API. Use depth-first search to efficiently identify the blobs.

public class BlobFinder
------------------------------------------------------------------------------------------------
// find all blobs in the picture using the luminance threshold tau
public BlobFinder(Picture picture, double tau)

// return the number of beads with >= P pixels
public int countBeads(int P)

// return all beads with >= P pixels
public Blob[] getBeads(int P)

The details about the BlobFinder constructor were mentioned in post #3. Make it so the constructor initializes the ArrayList<Blob> blobs field. Use depth-first-search to efficiently identify the blobs.

This field will be useful in the following methods.

Using a for each construct, or an iterator if you prefer, count the number of beads with ##\geq P## pixels and return the result. Remember ##P## is a command line argument.

Using the loop of your choice, return a reference to a Blob[] array containing all the blobs with ##\geq P## pixels and return the result.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 16 ·
Replies
16
Views
13K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K