Skip to content

Commit cb4218d

Browse files
committed
CF 1.4
new methods.
1 parent 8b5aeb8 commit cb4218d

File tree

5 files changed

+147
-42
lines changed

5 files changed

+147
-42
lines changed

Catalano.Image/src/Catalano/Imaging/FastBitmap.java

+60-34
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ public FastBitmap(FastBitmap fastBitmap){
129129
*/
130130
public FastBitmap(BufferedImage bufferedImage) {
131131
this.bufferedImage = bufferedImage;
132-
if (getType() == BufferedImage.TYPE_3BYTE_BGR) {
133-
toRGB();
134-
}
135-
setCoordinateSystem(CoordinateSystem.Matrix);
132+
prepare();
136133
refresh();
137134
}
138135

@@ -142,10 +139,7 @@ public FastBitmap(BufferedImage bufferedImage) {
142139
*/
143140
public FastBitmap(Image image) {
144141
bufferedImage = (BufferedImage)image;
145-
if (getType() == BufferedImage.TYPE_3BYTE_BGR) {
146-
toRGB();
147-
}
148-
setCoordinateSystem(CoordinateSystem.Matrix);
142+
prepare();
149143
refresh();
150144
}
151145

@@ -155,10 +149,7 @@ public FastBitmap(Image image) {
155149
*/
156150
public FastBitmap(ImageIcon ico){
157151
bufferedImage = (BufferedImage)ico.getImage();
158-
if (getType() == BufferedImage.TYPE_3BYTE_BGR) {
159-
toRGB();
160-
}
161-
setCoordinateSystem(CoordinateSystem.Matrix);
152+
prepare();
162153
refresh();
163154
}
164155

@@ -169,16 +160,7 @@ public FastBitmap(ImageIcon ico){
169160
public FastBitmap(String pathname){
170161
try {
171162
this.bufferedImage = ImageIO.read(new File(pathname));
172-
setCoordinateSystem(CoordinateSystem.Matrix);
173-
if (getType() == BufferedImage.TYPE_BYTE_GRAY) {
174-
refresh();
175-
}
176-
else if (getType() == BufferedImage.TYPE_INT_ARGB || getType() == BufferedImage.TYPE_4BYTE_ABGR){
177-
toARGB();
178-
}
179-
else{
180-
toRGB();
181-
}
163+
prepare();
182164
} catch (IOException ex) {
183165
ex.printStackTrace();
184166
}
@@ -208,8 +190,8 @@ public FastBitmap(int width, int height, ColorSpace colorSpace){
208190
else if(colorSpace == ColorSpace.Grayscale){
209191
bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
210192
}
211-
else if(colorSpace == ColorSpace.RGB){
212-
bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
193+
else if(colorSpace == ColorSpace.ARGB){
194+
bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
213195
}
214196

215197
this.setCoordinateSystem(CoordinateSystem.Matrix);
@@ -232,12 +214,32 @@ public FastBitmap(int[][] image){
232214
* @param image Array.
233215
*/
234216
public FastBitmap(int[][][] image){
235-
bufferedImage = new BufferedImage(image[0].length, image.length, BufferedImage.TYPE_INT_RGB);
217+
if (image[0][0].length == 3)
218+
bufferedImage = new BufferedImage(image[0].length, image.length, BufferedImage.TYPE_INT_RGB);
219+
else{
220+
bufferedImage = new BufferedImage(image[0].length, image.length, BufferedImage.TYPE_INT_ARGB);
221+
}
236222
this.setCoordinateSystem(CoordinateSystem.Matrix);
237223
refresh();
238224
arrayToImage(image);
239225
}
240226

227+
/**
228+
* Prepare the Fast Bitmap;
229+
*/
230+
private void prepare(){
231+
if (getType() == BufferedImage.TYPE_BYTE_GRAY) {
232+
refresh();
233+
}
234+
else if (getType() == BufferedImage.TYPE_INT_ARGB || getType() == BufferedImage.TYPE_4BYTE_ABGR){
235+
toARGB();
236+
}
237+
else{
238+
toRGB();
239+
}
240+
setCoordinateSystem(CoordinateSystem.Matrix);
241+
}
242+
241243
/**
242244
* Refresh raster and get data buffer from raster.
243245
*/
@@ -544,9 +546,17 @@ public void arrayToImage(double image[][]){
544546
* @param image Array.
545547
*/
546548
public void arrayToImage(int image[][][]){
547-
for (int x = 0; x < image.length; x++) {
548-
for (int y = 0; y < image[0].length; y++) {
549-
setRGB(x, y, image[x][y][0], image[x][y][1], image[x][y][2]);
549+
if (image[0][0].length == 3)
550+
for (int x = 0; x < image.length; x++) {
551+
for (int y = 0; y < image[0].length; y++) {
552+
setRGB(x, y, image[x][y][0], image[x][y][1], image[x][y][2]);
553+
}
554+
}
555+
else{
556+
for (int x = 0; x < image.length; x++) {
557+
for (int y = 0; y < image[0].length; y++) {
558+
setARGB(x, y, image[x][y][0], image[x][y][1], image[x][y][2], image[x][y][3]);
559+
}
550560
}
551561
}
552562
}
@@ -556,9 +566,17 @@ public void arrayToImage(int image[][][]){
556566
* @param image Array.
557567
*/
558568
public void arrayToImage(float image[][][]){
559-
for (int x = 0; x < image.length; x++) {
560-
for (int y = 0; y < image[0].length; y++) {
561-
setRGB(x, y, (int)image[x][y][0], (int)image[x][y][1], (int)image[x][y][2]);
569+
if (image[0][0].length == 3)
570+
for (int x = 0; x < image.length; x++) {
571+
for (int y = 0; y < image[0].length; y++) {
572+
setRGB(x, y, (int)image[x][y][0], (int)image[x][y][1], (int)image[x][y][2]);
573+
}
574+
}
575+
else{
576+
for (int x = 0; x < image.length; x++) {
577+
for (int y = 0; y < image[0].length; y++) {
578+
setARGB(x, y, (int)image[x][y][0], (int)image[x][y][1], (int)image[x][y][2], (int)image[x][y][3]);
579+
}
562580
}
563581
}
564582
}
@@ -568,9 +586,17 @@ public void arrayToImage(float image[][][]){
568586
* @param image Array.
569587
*/
570588
public void arrayToImage(double image[][][]){
571-
for (int x = 0; x < image.length; x++) {
572-
for (int y = 0; y < image[0].length; y++) {
573-
setRGB(x, y, (int)image[x][y][0], (int)image[x][y][1], (int)image[x][y][2]);
589+
if (image[0][0].length == 3)
590+
for (int x = 0; x < image.length; x++) {
591+
for (int y = 0; y < image[0].length; y++) {
592+
setRGB(x, y, (int)image[x][y][0], (int)image[x][y][1], (int)image[x][y][2]);
593+
}
594+
}
595+
else{
596+
for (int x = 0; x < image.length; x++) {
597+
for (int y = 0; y < image[0].length; y++) {
598+
setARGB(x, y, (int)image[x][y][0], (int)image[x][y][1], (int)image[x][y][2], (int)image[x][y][3]);
599+
}
574600
}
575601
}
576602
}

Catalano.MachineLearning/src/Catalano/MachineLearning/KNearestNeighbors.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
1+
// Catalano Machine Learning Library
2+
// The Catalano Framework
3+
//
4+
// Copyright © Diego Catalano, 2013
5+
// diego.catalano at live.com
6+
//
7+
//
8+
// This library is free software; you can redistribute it and/or
9+
// modify it under the terms of the GNU Lesser General Public
10+
// License as published by the Free Software Foundation; either
11+
// version 2.1 of the License, or (at your option) any later version.
12+
//
13+
// This library is distributed in the hope that it will be useful,
14+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
// Lesser General Public License for more details.
17+
//
18+
// You should have received a copy of the GNU Lesser General Public
19+
// License along with this library; if not, write to the Free Software
20+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+
//
622

723
package Catalano.MachineLearning;
824

Catalano.Math/src/Catalano/Math/Matrix.java

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package Catalano.Math;
2323

2424
import Catalano.Core.IntPoint;
25+
import java.lang.reflect.Array;
2526

2627
/**
2728
* Defines a set of methods that works on multidimensional arrays and vectors.
@@ -1146,6 +1147,23 @@ public static float[][] Transpose(float[][] A){
11461147
return t;
11471148
}
11481149

1150+
/**
1151+
* Gets the transpose of the matrix.
1152+
* @param <E> Object.
1153+
* @param A Matrix.
1154+
* @return Transposed matrix.
1155+
*/
1156+
public static <E> E[][] Transpose(E[][] A){
1157+
E[][] t = (E[][])Array.newInstance(A[0][0].getClass(), A[0].length, A.length);
1158+
1159+
for (int i = 0; i < A.length; i++) {
1160+
for (int j = 0; j < A[0].length; j++) {
1161+
t[j][i] = A[i][j];
1162+
}
1163+
}
1164+
return t;
1165+
}
1166+
11491167
/**
11501168
* Gets the Identity matrix of the given size.
11511169
* @param order Size.

Catalano.Math/src/Catalano/Math/Transforms/FourierTransform.java

+41-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private static void convolve(double[] xreal, double[] ximag, double[] yreal, dou
374374
* @param x Data.
375375
* @param direction Transformation direction.
376376
*/
377-
public static void FFTShift(double[] x, Direction direction) {
377+
public static void FFTShift1D(double[] x, Direction direction) {
378378

379379
if (x.length == 1)
380380
return;
@@ -406,4 +406,44 @@ public static void FFTShift(double[] x, Direction direction) {
406406
}
407407
}
408408
}
409+
410+
/**
411+
* Shift zero-frequency component to center of spectrum.
412+
* @param <E> Object.
413+
* @param x Data.
414+
* @param direction Transformation direction.
415+
*/
416+
public static <E> void FFTShift1D(E[] x, Direction direction) {
417+
418+
if (x.length == 1)
419+
return;
420+
421+
E[] temp = x.clone();
422+
int move = x.length / 2;
423+
424+
if(direction == Direction.Forward){
425+
int c = 0;
426+
for (int i = x.length - move; i < x.length; i++) {
427+
x[c] = temp[i];
428+
c++;
429+
}
430+
431+
for (int i = 0; i < x.length - move; i++) {
432+
x[c] = temp[i];
433+
c++;
434+
}
435+
}
436+
else{
437+
int c = 0;
438+
for (int i = move; i < x.length; i++) {
439+
x[move+c] = temp[c];
440+
c++;
441+
}
442+
443+
for (int i = 0; i < move; i++) {
444+
x[i] = temp[move+i];
445+
}
446+
}
447+
}
448+
409449
}

Roadmap.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Version updates and fixes:
2323
- Added: get; setRGBData method.
2424
- Added: get; setGrayData method.
2525

26+
- Fixed: some constructors in FastBitmap when are loading argb images.
27+
2628
* Catalano.Image.Filters
2729
- New: Separable Convolution.
2830
- New: Image Pyramids.
@@ -77,8 +79,7 @@ Version updates and fixes:
7779
* Catalano.Math
7880
- New: Taylor Series.
7981

80-
- Fixed: FFT, FFT2 in Fourier Transform. Now is working in Asymetric scaling. Removed power of 2 limitation in FFT and FFT2.
81-
82+
- Added: generic Transpose in Matrix.
8283
- Added: getReal, getImaginary in ComplexNumber for 1,2 dimensions.
8384
- Added: Sum in Matrix.
8485
- Added: CreateMatrix2D in Matrix.
@@ -103,6 +104,10 @@ Version updates and fixes:
103104
* Catalano.Math.Transforms
104105
- New: Fast Hilbert Transform.
105106

107+
- Added: FFTShift in Fourier Transform.
108+
109+
- Fixed: FFT, FFT2 in Fourier Transform. Now is working in Asymetric scaling. Removed power of 2 limitation in FFT and FFT2.
110+
106111
* Catalano.Statistics
107112
- New: Dissimilarity.
108113
- New: Approximation.

0 commit comments

Comments
 (0)