I want to display histogram of image color channels.
At first my reading of pixels looks like:
for(int i=0; i<width; i++)
for(int j=0; j<height; j++) {
data=writeableRaster.getDataElements(i, j, null);
red=colorModel.getRed(data);
green=colorModel.getGreen(data);
blue=colorModel.getBlue(data);
rgb=(red+green+blue)/3;
++redL[red];
++greenL[green];
++blueL[blue];
++rgbL[rgb];
}
}
I also have additional method for creating chart with given channel colors table:
int number = channelHistogram.length;
HistogramDataset dataset = new HistogramDataset();
dataset.setType(HistogramType.RELATIVE_FREQUENCY);
dataset.addSeries("Hist",channelHistogram,number);
String plotTitle = "Hist";
String xaxis = "number";
String yaxis = "value";
PlotOrientation orientation = PlotOrientation.VERTICAL;
boolean show = false;
boolean toolTips = false;
boolean urls = false;
JFreeChart chart = ChartFactory.createHistogram( plotTitle, xaxis, yaxis,
dataset, orientation, show, toolTips, urls);
But chart is wrong displayed. It means at Y axis there are "low" values (from ~ 0 - 0.09) and at X axis there aren't values from scope 0 - 255.
Any help?
dataset.setType(HistogramType.RELATIVE_FREQUENCY);
Can you try setting different options here and see if it helps? Also if you can show what channelHistogram field contains that may be helpful to debug.
Related
I want to draw Pie_chart for small data set has this form.
I used these code
DefaultPieDataset my_pie_chart_data = new DefaultPieDataset();
for(int i =1; i<9; i++) {
row = my_sheet.getRow(0);
cell = row.getCell(i);
chart_label=cell.getStringCellValue();
row = my_sheet.getRow(1);
cell = row.getCell(i);
chart_data=cell.getNumericCellValue();
my_pie_chart_data.setValue(chart_label,chart_data);
}
JFreeChart myPieChart=ChartFactory.createPieChart("PIE",my_pie_chart_data,true,true,false);
int width=640; /* Width of the chart */
int height=480; /* Height of the chart */
float quality=1; /* Quality factor */
ByteArrayOutputStream chart_out = new ByteArrayOutputStream();
ChartUtilities.writeChartAsJPEG(chart_out,quality,myPieChart,width,height);
int my_picture_id = my_workbook.addPicture(chart_out.toByteArray(), Workbook.PICTURE_TYPE_JPEG);
chart_out.close();
XSSFDrawing drawing = my_sheet.createDrawingPatriarch();
ClientAnchor my_anchor = new XSSFClientAnchor();
my_anchor.setCol1(4);
my_anchor.setRow1(5);
XSSFPicture my_picture = drawing.createPicture(my_anchor, my_picture_id);
my_picture.resize();
chart_file_input.close();
}
the resulting chart has these label on it, which is confusing, specially when the values are small because, they all refer to the same section. And I can live with the legend definition below.
Does anybody know how can I delete them ?
I am working with a large array of dots (4096x256) to be displayed as an image in a JavaFX application. I started with a BMP image built from the 2D array of dots, but the zooming operation produced a blurred image on screen. So, I decided to use SVGPath to draw my image which now zooms in properly (no blur) with a simple SVGPath content, but becomes veeeeeery slow when it comes to displaying a checkerboard of two colors, probably because the SVGPath content is so large for fail bits information, as shown in my code.
Is there an efficient way to achieve this? By efficient, I mean fast execution time while keeping the pixel-sharp zooming effect.
public Group createImage(final int width, final int height, final int boxIdx)
{
// assuming that pass data bits are more numerous than others, we can
// start by drawing full green colored lines
StringBuilder svgPass = new StringBuilder();
for (int y = 0; y < height; y++)
{
svgPass.append("M0,");
svgPass.append(Integer.toString(y));
svgPass.append(" ");
svgPass.append("L0,");
svgPass.append(Integer.toString(y));
svgPass.append(" ");
svgPass.append(Integer.toString(width - 1));
svgPass.append(",");
svgPass.append(Integer.toString(y));
svgPass.append(" z");
}
SVGPath imgPass = new SVGPath();
imgPass.setContent(svgPass.toString());
imgPass.setStrokeLineJoin(StrokeLineJoin.BEVEL);
imgPass.setStroke(Color.GREEN);
imgPass.setStrokeWidth(1);
// fail data bits
StringBuilder svgFail = new StringBuilder();
Bit[][] bits = WordLineManager.getInstance().getBlocksMap().get(boxIdx);
for (int y = 0; y < bits.length; y++)
{
for (int x = 0; x < bits[0].length; x++)
{
if (bits[y][x].getNature() == BitNature.DATA && !bits[y][x].getStatus())
{
svgFail.append("M");
svgFail.append(Integer.toString(x));
svgFail.append(",");
svgFail.append(Integer.toString(y));
svgFail.append(" ");
svgFail.append("L");
svgFail.append(Integer.toString(x));
svgFail.append(",");
svgFail.append(Integer.toString(y));
svgFail.append(" ");
svgFail.append(Integer.toString(x + 1));
svgFail.append(",");
svgFail.append(Integer.toString(y));
svgFail.append(" z");
}
}
}
SVGPath imgFail = new SVGPath();
imgFail.setContent(svgFail.toString());
imgFail.setStrokeLineJoin(StrokeLineJoin.BEVEL);
imgFail.setStroke(Color.RED);
imgFail.setStrokeWidth(1);
return new Group(imgPass, imgFail);
}
I'm new to Slick2D, and I'm using Tiled to make .tmx map.
for (int xAxis = 0; xAxis < map.getWidth(); xAxis++) {
for (int yAxis = 0; yAxis < map.getHeight(); yAxis++) {
int tileID = map.getTileId(xAxis, yAxis, 0);
String value = map.getTileProperty(tileID, "blocked", "0");
int valueInInt = Integer.parseInt(value);
if (valueInInt == 1) {
blocked[xAxis][yAxis] = true;
}
}
}
This works fine when the blocks are on the same layer with others, however, if I put the blocks on a different Tile layer, I can't get the right TileProperty anymore.
Why did it happen? What can I do with that or any ideals?
Thanks a lot.
The third parameter to TiledMap.getTileId() is the layerIndex. You would have to use that to select the layer where you're searching for tiles with the "blocked" property set to "1".
I'm trying to make a ColorGrid graph that has the center square being a dark color and the squares around it slowly fading to white as it gets farther. I'm new to TeeChart and I checked out the examples. I'm trying to replace the series.fillSampleValues() but I'm not sure what values to include in series.add(). What are the parameters for the series.add() for ColorGrid?
Here's my code
final LinearLayout ll = (LinearLayout) findViewById( R.id.samplegraphlayout );
TChart chart = new TChart( ll.getContext() );
ll.addView( chart );
Series series = null;
try {
series = Series.createNewSeries(chart.getChart(), ColorGrid.class, null);
} catch (Exception e) {
e.printStackTrace();
}
series.fillSampleValues();
chart.addSeries(series);
chart.getLegend().setAlignment(LegendAlignment.BOTTOM);
chart.getHeader().setText("ColorGrid Series");
chart.getHeader().getFont().setSize(14);
Here it is an example of how you could populate a ColorGrid with Random Colors:
tChart1.getAspect().setView3D(false);
int gridWidth = 11;
int gridHeight = 11;
ColorGrid colorGrid1 = new ColorGrid(tChart1.getChart());
colorGrid1.setColorEach(true);
for (int x=0; x<gridWidth; x++) {
for (int z=0; z<gridHeight; z++) {
colorGrid1.add(x, 1, z, new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
}
}
Then, knowing the column (x) and row (z) of each cell, you shouldn't find too much problems to calculate the Color that corresponds to each one.
I have a method for generating dataset:
private CategoryDataset createDataset(double[] arr,
String seriesName) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (int i = 0; i < arr.length; i++) {
dataset.addValue(arr[i], "mySeries", new Integer(i));
}
return dataset;
}
and create BarChart:
JFreeChart chart = ChartFactory.createBarChart(chartTitle,
xaxis, // domain axis label
yaxis, // range axis label
dataset, // data
orientation, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
Array of doubles hold histogram data, so there are 255 values.
When I display chart there are labels for
all values from 0 - 255 on x axis. I want display only labels for several indexes (for example: 0, 10, 20, 30). I saw that in RangeAxis there is setStandardTickUnits method. But in CategoryAxis:
CategoryAxis domainAxis = plot.getDomainAxis();
I didn't find this.
Any help?
You can try as follows,
NumberAxis vn = (NumberAxis) plot.getRangeAxis();
vn.setTickUnit(new NumberTickUnit(10d));
vn.setRange(0D, Math.ceil(factor * MAX_VALUE));
--that is you just need cast plot.getRangeAxis() to NumberAxis type.
I had same problem. I created new class implementing 'Comparable', and use it as last parameter in addValue(...). You can create something like
class MyCategory implements Comparable<MyCategory> {
Integer value;
String stValue;
MyCategory(int val) {
value = val;
stValue = val%10==0?""+val:"";}
public int compareTo(MyCategory key) { return value.compareTo(key.value); }
public String toString() { return stValue; }
}
And then instead of
dataset.addValue(arr[i], "mySeries", new Integer(i));
use
dataset.addValue(arr[i], "mySeries", new MyCategory(i));