Skip to content
Snippets Groups Projects
Commit cb97991b authored by ik1g19's avatar ik1g19
Browse files

add comments

parent 48a1dce8
No related branches found
No related tags found
No related merge requests found
package uk.ac.soton.ecs.ik1g19.hybridimages; package uk.ac.soton.ecs.ik1g19.hybridimages;
import jAudioFeatureExtractor.AudioFeatures.FeatureExtractor;
import org.openimaj.image.DisplayUtilities; import org.openimaj.image.DisplayUtilities;
import org.openimaj.image.FImage; import org.openimaj.image.FImage;
import org.openimaj.image.ImageUtilities; import org.openimaj.image.ImageUtilities;
......
...@@ -6,6 +6,7 @@ import org.openimaj.image.processor.SinglebandImageProcessor; ...@@ -6,6 +6,7 @@ import org.openimaj.image.processor.SinglebandImageProcessor;
public class MyConvolution implements SinglebandImageProcessor<Float, FImage> { public class MyConvolution implements SinglebandImageProcessor<Float, FImage> {
//templated to be used during convolution
private float[][] kernel; private float[][] kernel;
...@@ -15,14 +16,13 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> { ...@@ -15,14 +16,13 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> {
} }
/**
* @desc Perform template convolution on given image
* @param image Image to be transformed
*/
@Override @Override
public void processImage(FImage image) { public void processImage(FImage image) {
// convolve image with kernel and store result back in image //temp image for writing values to during convolution
//
// hint: use FImage#internalAssign(FImage) to set the contents
// of your temporary buffer image to the image.
FImage tmpImg = image.clone(); FImage tmpImg = image.clone();
//border size on left and right is half kernel width //border size on left and right is half kernel width
...@@ -42,8 +42,8 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> { ...@@ -42,8 +42,8 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> {
//convolve template lol //convolve template lol
for (int x = 0 - bLR; x < imgW - 1 - bLR; x++) { //all columns minus border for (int x = 0 - bLR; x < imgW - 1 - bLR; x++) { //traverse columns, start from zero padding
for (int y = 0 - bTB; y < imgH - 1 - bTB; y++) { //all rows minus border for (int y = 0 - bTB; y < imgH - 1 - bTB; y++) { //traverse rows, start from zero padding
float sum = 0f; float sum = 0f;
for (int kX = 0; kX < kW; kX++) { //all points in the kernel for (int kX = 0; kX < kW; kX++) { //all points in the kernel
for (int kY = 0; kY < kH; kY++) { for (int kY = 0; kY < kH; kY++) {
...@@ -53,6 +53,7 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> { ...@@ -53,6 +53,7 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> {
//implicit zero-padding //implicit zero-padding
boolean outbounds = (cX < 0) || (cX > imgW - 1) || (cY < 0) || (cY > imgH - 1); boolean outbounds = (cX < 0) || (cX > imgW - 1) || (cY < 0) || (cY > imgH - 1);
//zero padding will not affect sum
if (!outbounds) { if (!outbounds) {
sum += image.getPixel(cX, cY) * //pixel value... sum += image.getPixel(cX, cY) * //pixel value...
kernel[kH - kY - 1][kW - kX - 1]; //multiplied with kernel value kernel[kH - kY - 1][kW - kX - 1]; //multiplied with kernel value
...@@ -63,6 +64,7 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> { ...@@ -63,6 +64,7 @@ public class MyConvolution implements SinglebandImageProcessor<Float, FImage> {
} }
} }
//replace original image with convolved image
image.internalAssign(tmpImg); image.internalAssign(tmpImg);
} }
......
...@@ -4,6 +4,10 @@ import org.openimaj.image.DisplayUtilities; ...@@ -4,6 +4,10 @@ import org.openimaj.image.DisplayUtilities;
import org.openimaj.image.MBFImage; import org.openimaj.image.MBFImage;
import org.openimaj.image.processing.convolution.Gaussian2D; import org.openimaj.image.processing.convolution.Gaussian2D;
/**
* @desc Combines low and high frequencies of two images to form a hybrid image
*/
public class MyHybridImages { public class MyHybridImages {
/** /**
* @desc Compute a hybrid image combining low-pass and high-pass filtered images * @desc Compute a hybrid image combining low-pass and high-pass filtered images
...@@ -21,29 +25,30 @@ public class MyHybridImages { ...@@ -21,29 +25,30 @@ public class MyHybridImages {
* @return the computed hybrid image * @return the computed hybrid image
*/ */
public static MBFImage makeHybrid(MBFImage lowImage, float lowSigma, MBFImage highImage, float highSigma) { public static MBFImage makeHybrid(MBFImage lowImage, float lowSigma, MBFImage highImage, float highSigma) {
//implement your hybrid images functionality here. //kernels for gaussian averaging
//Your submitted code must contain this method, but you can add
//additional static methods or implement the functionality through
//instance methods on the `MyHybridImages` class of which you can create
//an instance of here if you so wish.
//Note that the input images are expected to have the same size, and the output
//image will also have the same height & width as the inputs.
float[][] lowGausK = Gaussian2D.createKernelImage(gSigmaToSize(lowSigma), lowSigma).pixels; float[][] lowGausK = Gaussian2D.createKernelImage(gSigmaToSize(lowSigma), lowSigma).pixels;
float[][] highGausK = Gaussian2D.createKernelImage(gSigmaToSize(highSigma), highSigma).pixels; float[][] highGausK = Gaussian2D.createKernelImage(gSigmaToSize(highSigma), highSigma).pixels;
//convolution operators for gaussian averaging
MyConvolution gAvgLow = new MyConvolution(lowGausK); MyConvolution gAvgLow = new MyConvolution(lowGausK);
MyConvolution gAvgHigh = new MyConvolution(highGausK); MyConvolution gAvgHigh = new MyConvolution(highGausK);
//lowpass on first image
lowImage.processInplace(gAvgLow); lowImage.processInplace(gAvgLow);
MBFImage tmpHigh = highImage.process(gAvgHigh); //high pass on second image
highImage.subtractInplace(tmpHigh); MBFImage tmpHigh = highImage.process(gAvgHigh); //lowpass...
highImage.subtractInplace(tmpHigh); //subtracted from original image
//combine frequencies
return highImage.add(lowImage); return highImage.add(lowImage);
} }
/**
* @desc Helper function, find kernel size for given sigma
* @param sigma Given sigma value
* @return Appropriate kernel size
*/
private static int gSigmaToSize(float sigma) {int size = (int)(8.0f*sigma+1.0f); return size%2==0 ? size++ : size;} private static int gSigmaToSize(float sigma) {int size = (int)(8.0f*sigma+1.0f); return size%2==0 ? size++ : size;}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment