hey,
im doing a project on processing images and i'd like to extract the features of an image stored in databse.How can i do that? anyone help..,please..
hey,
im doing a project on processing images and i'd like to extract the features of an image stored in databse.How can i do that? anyone help..,please..
Can you Describe what you mean by a feature?
Are you reading an image from a database and want to know its size?
Can you Describe what you mean by a feature?
Are you reading an image from a database and want to know its size?
no..features like texture,color and shape of objects depicted etc...i wanted to search an image on an image database based upon these extracted features...
I don't know of any classes in Java SE that can do that. You should ask google if there are 3rd party packages that do what you are looking for
This will help you in reading the image properties, well some of them, at least:
Really depends on how you are storing the image in the database to begin with. Most proprietary image archives have some sort of meta data. Typically, this sort of meta data can be customized to meet your requirements. However, that would require initial data entry for some of your more subjective requirements (texture, shape of objects).
I suspect you are attempting to get some meta data from a simple byte stream or a BLOB. In this case, if you don't store meta data on the entry in the database, you'll need to extract the image and parse whatever data you want from it. Not ideal if you're doing a search feature. So, storing the meta data ahead of time will save you loads of processing time.
As I said before, texture and shape of objects inside an image are subjective and would take extremely sophisticated software to parse. Other "features" such as a size and color are easily extracted from an image.
Here's an easy way to get the color of an image:
import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import javax.imageio.ImageIO;
public class ImageParser {
/**
* Get the java.awt.Color of a pixel at a given point.
* @param point
* @param file
* @return
*/
public static Color getColorPoint(Point point, File file) {
Color color = null;
try {
BufferedImage image = ImageIO.read(file);
color = getColorAtPoint(point, image);
image.flush();
} catch (IOException e) {
e.printStackTrace();
}
return color;
}
/**
* Get the set of all java.awt.Color found in an image.
* @param point
* @param image
* @return
*/
public static Set<Color> getAllColors(File file) {
Set<Color> colors = new HashSet<Color>();
try {
BufferedImage image = ImageIO.read(file);
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
Color color = getColorAtPoint(new Point(x, y), image);
if (color != null && !colors.contains(color))
colors.add(color);
}
}
image.flush();
} catch (IOException e) {
e.printStackTrace();
}
return colors;
}
/**
* Bytes to java.awt.Color translator.
* @param point
* @param image
* @return
*/
private static Color getColorAtPoint(Point point, BufferedImage image) {
int colorBytes = image.getRGB(point.x, point.y);
return new Color(
(colorBytes & 0x00ff0000) >> 16,
(colorBytes & 0x0000ff00) >> 8,
(colorBytes & 0x000000ff));
}
}
Size is a simply getHeight/Width from a java.awt.Image object. See the javadocs for more information on that task: http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Image.html
Best of luck.
Really depends on how you are storing the image in the database to begin with. Most proprietary image archives have some sort of meta data. Typically, this sort of meta data can be customized to meet your requirements. However, that would require initial data entry for some of your more subjective requirements (texture, shape of objects).
I suspect you are attempting to get some meta data from a simple byte stream or a BLOB. In this case, if you don't store meta data on the entry in the database, you'll need to extract the image and parse whatever data you want from it. Not ideal if you're doing a search feature. So, storing the meta data ahead of time will save you loads of processing time.
As I said before, texture and shape of objects inside an image are subjective and would take extremely sophisticated software to parse. Other "features" such as a size and color are easily extracted from an image.
Here's an easy way to get the color of an image:
import java.awt.Color; import java.awt.Point; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.HashSet; import java.util.Set; import javax.imageio.ImageIO; public class ImageParser { /** * Get the java.awt.Color of a pixel at a given point. * @param point * @param file * @return */ public static Color getColorPoint(Point point, File file) { Color color = null; try { BufferedImage image = ImageIO.read(file); color = getColorAtPoint(point, image); image.flush(); } catch (IOException e) { e.printStackTrace(); } return color; } /** * Get the set of all java.awt.Color found in an image. * @param point * @param image * @return */ public static Set<Color> getAllColors(File file) { Set<Color> colors = new HashSet<Color>(); try { BufferedImage image = ImageIO.read(file); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { Color color = getColorAtPoint(new Point(x, y), image); if (color != null && !colors.contains(color)) colors.add(color); } } image.flush(); } catch (IOException e) { e.printStackTrace(); } return colors; } /** * Bytes to java.awt.Color translator. * @param point * @param image * @return */ private static Color getColorAtPoint(Point point, BufferedImage image) { int colorBytes = image.getRGB(point.x, point.y); return new Color( (colorBytes & 0x00ff0000) >> 16, (colorBytes & 0x0000ff00) >> 8, (colorBytes & 0x000000ff)); } }
Size is a simply getHeight/Width from a java.awt.Image object. See the javadocs for more information on that task: http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Image.html
Best of luck.
hey, thanks for ur reply first....can u please explain this part of ur program
return new Color(
(colorBytes & 0x00ff0000) >> 16,
(colorBytes & 0x0000ff00) >> 8,
(colorBytes & 0x000000ff));
}
and now we got the the set of colors of an image right...how can we comapare two images using this color set?? actually im trying to implement a system for searching images based in an input query image...
no..features like texture,color and shape of objects depicted etc...i wanted to search an image on an image database based upon these extracted features...
I don't want to discourage you, but identifying and encoding info like texture or shape is a really really difficult computational problem, in any language. Is there anything else you could be doing instead for this project?
I don't want to discourage you, but identifying and encoding info like texture or shape is a really really difficult computational problem, in any language. Is there anything else you could be doing instead for this project?
sir,
we know this is very diffiicult,but we have to do this....Its a part of our final year project.These are the primary requirements ,we have to optimize the search using genetic algorithm too...we are trying our best and confident that we can do if someone could really help us ..:)
OK. That's going to be a very interesting project - I'm sure that many of us here will be following it and trying to contribute!
You are certainly going to need some code along the lines of ztini's post above. You'll almost certainly run into some performance issues combining image processing and genetic algorithms, so it's probably worth some fine-tuning of the lower-level methods - have a look at the PixelGrabber class to give access to multiple pixels in a very efficient way.
ztini's code that you asked about is to extract the three colour components is based on the assumption that the image is internally stored as one int per pixel, with the four bytes of the int holding Alpha, R, G, B values. It uses bit-shifting and masking to extract the RGB bytes into separate ints.
Comparing images by colour set? Rather than just building a collection of every colour in the image, you may do better to build a histrogram that shows how many of each colour is present, eg so the peak of the histogram will be the predominant colour. with (2 power 24) colours you'll need to compact it a bit, eg by having 3 256-element histograms for RGB separately, or by "posterising" the image into a smaller number of colours, eg by ignoring the last 3 or 4 bits of each color component.
hey,
i've got the 3 band color histogram of an image...i've used the code:-
PlanarImage img = JAI.create("fileload",file_name );
int[] bins = {256, 256, 256}; // The number of bins.
double[] low = {0.0D, 0.0D, 0.0D}; // The low value.
double[] high = {256.0D, 256.0D, 256.0D}; // The high value.
// Create the parameter block.
ParameterBlock pb = new ParameterBlock();
pb.addSource(img); // Specify the source image
pb.add(null); // No ROI
pb.add(1); // Sampling
pb.add(1); // periods
pb.add(bins);
pb.add(low);
pb.add(high);
// Perform the histogram operation.
PlanarImage dst = (PlanarImage)JAI.create("histogram", pb, null);
// Retrieve the histogram data.
Histogram hist = (Histogram) dst.getProperty("histogram");
// Print 3-band histogram.
for (int i=0; i< hist.getNumBins().length; i++) {
System.out.println(hist.getBinSize(0, i) + " " +hist.getBinSize(1,i)+ " " +hist.getBinSize(2, i) + " " );
}
the same process is repeated to extract and store the histograms of all images in the Mysql database when adding an image.Now i'd like to compare the histograme of an image submitted as query to the histograms of stored images..How can i do that?Anyone help please....
like to compare the histograme
Define what the structure of your histogram is and what the results of comparing two of them would be?
the histogram for an image will print the 3 bands since we used 3 "bins" in our program.The sample output is like :-
37658 6 0
456 256 13
47584 0 6
You show 3 rows of numbers with 3 numbers on a row.
When you compare those three rows of three numbers,
what would the results be?
Row by row,
col by col,
item by item
sum of row vs sum of row
etc
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.