Wannabree
Wannabree
JCHJava Community | Help. Code. Learn.
Created by Wannabree on 4/13/2025 in #java-help
LUT get index from .txt file
Hello, beginner here. In class we're currently working with OpenCV for image manipulation. We're asked to create a LookUpTable as a .txt file and and change the color of some pixels in an image. the .txt file is something like this:
000 255 000
255 000 000
000 000 255
255 255 255
000 255 000
255 000 000
000 000 255
255 255 255
I know that I can use a Scanner to read the values etc. but let's assume i just want the value 255 from col3 row3. Is there a direct way to access that value or do it have to loop through each line/value until i get to that point? I tried using FileReader and BufferReader but I haven't found way to read a specific value. My inital idea was it to read every value in the LUT and create an array so i don't have to loop through the whole table to get a single entry but that kind of destroys the purpose of a LUT. TL;DR is there a way to call a specific index from the LUT using only a .txt file?
4 replies
JCHJava Community | Help. Code. Learn.
Created by Wannabree on 4/8/2025 in #java-help
Call method from different class in a different package (beginner)
Hello, i have the following Problem: I have a class Histogramm.java inside a package Basis And my Main.java inside the package Main Histogramm.java has a function i want to call from Main.java
package Basis;

import java.util.*;
import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import Main.Aufgaben02;

public class Histogramm {

//other methods etc

public int[] gibHistogrammDaten(Mat bildMatrix) {
int[] histogramm = new int[256];
for(int i = 0; i<bildMatrix.rows();i++) {
for(int j = 0; j<bildMatrix.cols(); j++) {
double[] temp = bildMatrix.get(i,j);
histogramm[(int)temp[0]]++;
}
}
return histogramm;
}
}
package Basis;

import java.util.*;
import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import Main.Aufgaben02;

public class Histogramm {

//other methods etc

public int[] gibHistogrammDaten(Mat bildMatrix) {
int[] histogramm = new int[256];
for(int i = 0; i<bildMatrix.rows();i++) {
for(int j = 0; j<bildMatrix.cols(); j++) {
double[] temp = bildMatrix.get(i,j);
histogramm[(int)temp[0]]++;
}
}
return histogramm;
}
}
in my Main.java file i have a a Matrix that i want to pass to the gibHistogrammDaten(Mat bildMatrix) method.
package Main;

import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import Basis.Histogramm.*;

import java.util.*;

import Basis.Bild;

public class Aufgaben02 {

public static void main(String[] args) {

//more code not relevant to the question

Histogramm lel = new Histogramm();
Mat hilfeOne = Imgcodecs.imread("Bilder/Blume.jpg", Imgcodecs.IMREAD_UNCHANGED);
int[] histogramm = new int[256];
}
package Main;

import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import Basis.Histogramm.*;

import java.util.*;

import Basis.Bild;

public class Aufgaben02 {

public static void main(String[] args) {

//more code not relevant to the question

Histogramm lel = new Histogramm();
Mat hilfeOne = Imgcodecs.imread("Bilder/Blume.jpg", Imgcodecs.IMREAD_UNCHANGED);
int[] histogramm = new int[256];
}
I've been trying to call that method for a couple hours now. I tried setting the method to static public static int[] gibHistogrammDaten(Mat bildMatrix) which didn't work. I also tried creating an object of Histogramm lel = new Histogramm(); to go the route of int[] histogramm = lel.gibHistogrammDaten(hilfeOne); but that didn't work either. Next try was
int[] histogramm = new int[256];
histogram = gibHistogrammDaten(hilfeOne);
int[] histogramm = new int[256];
histogram = gibHistogrammDaten(hilfeOne);
which just tells me "The method gibHistogrammDaten(Mat) is undefined for the type Aufgaben02" Pretty much every answer i've found on google didn't work.
4 replies