Question: Can you check my Histogram.java? My logic there might be wrong and that's leading to incorrect similarity measurements Expected output for 'input _ files /
Can you check my Histogram.java? My logic there might be wrong and that's leading to incorrect similarity measurements
Expected output for 'inputfilescorrectfilestxt
or
My output: for 'inputfilescorrectfilestxt
import java.util.List;
import java.util.ArrayList;
public class Histogram
private double histogram;
public Histogramdouble histogram
this.histogram histogram;
public double getData
return histogram;
public boolean isEmpty
return histogram null histogram.length ;
Method to calculate the similarity score
public double similarityHistogram other
double similarityScore ;
if thishistogram.length other.histogram.length
throw new IllegalArgumentExceptionHistograms must have the same length for comparison.";
for int i ; i this.histogram.length; i
similarityScore Math.minthishistogrami other.histogrami;
return similarityScore;
Additional method to split the image into quarters and calculate histograms for each
public static List getQuartersHistogramdouble imagePixels
List quarters new ArrayList;
Divide the image into quarters each x
for int quarter ; quarter ; quarter
double quarterPixels getQuarterPixelsimagePixels quarter;
Histogram quarterHistogram calculateNormalizedHistogramquarterPixels;
quarters.addquarterHistogram;
return quarters;
private static double getQuarterPixelsdouble imagePixels, int quarter
double quarterPixels new double;
int startX quarter quarter : ;
int startY quarter quarter : ;
Copy the x block of pixels into quarterPixels
for int x ; x ; x
for int y ; y ; y
quarterPixelsxy imagePixelsstartX xstartY y;
return quarterPixels;
public static Histogram calculateNormalizedHistogramdouble quarterPixels
int histogram new int; For intensity levels
double totalPixels ; Total number of pixels in the quarter
Ensure the pixel values fall within the range
for int x ; x ; x
for int y ; y ; y
int pixelValue Math.min Math.maxint quarterPixelsxy;
histogrampixelValue;
Normalize the histogram
double normalizedHistogram new double;
for int i ; i histogram.length; i
normalizedHistogrami histogrami totalPixels;
return new HistogramnormalizedHistogram;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
