Closed Thread Icon

Topic awaiting preservation: Image Processing with Java (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12103" title="Pages that link to Topic awaiting preservation: Image Processing with Java (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Image Processing with Java <span class="small">(Page 1 of 1)</span>\

 
aerosoul
Paranoid (IV) Inmate

From: Cell block #4
Insane since: Jun 2001

posted posted 03-11-2002 15:15

Hey,

I need some help/guidance/whatever. I've been looking around the web a lot, and I still can't find help on a problem that would appear rather simple to anyone who has dealt with images in Java.

I need to load a greyscale image, display it, convert it to an array of floats, perform some operation on it, convert the new array back into an image, and display it next to the original. The operation I'm performing deals with image compression, and I've got the mathematics behind it figured out. It's the coding part that is beginning to worry me. (Ordinarily, this isn't meant to be a hard project as the people who are taking this Calculus course have already completed the Java course - unfortunately I placed out of the prereqs for this course and reached here with no Java experience).

Okay these are the parts that make sense to me:

Loading the image: Pretty straightforward(?). I used
Image theImage = Toolkit.getDefaultToolkit().getImage(filename);

Displaying the image: This is where it gets confusing. Every where I try to read up about it, the OO approach would involve frames/containers/panels/components/etc and I have no idea what any of those are. What would be a quick easy way to just show the image on the screen? As an alternative, I could write it to a file, but since the project involves Image Compression, I would have to read and write to non-compressed formats, which excludes GIF/JPG and makes loading the image that much harder.

Converting image to an array: I think I have this part covered. I just plan to get an array of ints, convert to HSB, retrieve the brightness component and store it as a float in an array of floats.

Mathematical operation: That's the one part I know how to do.

Converting array to an image: Okay I can use MemoryImageSource to convert an int array into an image. Question is, how do I convert a float representing the brightness of a grayscale pixel, into an int representing the RGB color?

Displaying altered image: This, I would guess, ties back in to the same problem as the first one.


I'm not even sure if this is the right forum, but I'm getting desperate - the more I look it up and at the API documentation - the more confused I get.


Anyone willing to point me in the right direction?!


Thanks a lot,

aero

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-11-2002 18:04

This may above the heads of people around here. Don't think anyone here is a graphics programmer. I think my coursework may take me in this direction soon, and I've taken Java, but never used those APIs.

Here's my question, why is the brigtness in floats rather than ints? Since I have little knowledge of internal representations of images other than uncompressed RGB, I can't help you, but it seems to me that you need to define what formats you are using, then figure out algorithms to switch between them. Then you just loop through the arrays, perform the transformation on an element and assign it to a new array. I might be able to help you with the math if you can define the formats specifically, but no guarantees.

[edit]Looking back on your post it looks like you are just confused about the graphics APIs and Java data structures. I have no experience with the aforementioned data structures, but it sounds like a good question for your teacher. One semester of Java doens't cover all that stuff at my school.[/edit]

-jiblet

[This message has been edited by jiblet (edited 03-11-2002).]

aerosoul
Paranoid (IV) Inmate

From: Cell block #4
Insane since: Jun 2001

posted posted 03-11-2002 19:27

Well the reason that the brightness values are in floats is

a) because Java's conversion method automatically returns floats
b) because I need to keep track of it as a value between 0 and 1

I'm not quite sure what you mean by 'define the formats'

I think the closest I could get to that would be

a) Gif/Jpeg/Bmp/Whatever (The format the image is going to be read in as)
b) The internal Java 'Image' class format
c) Integer arrays of RGB
d) Float arrays of brightness
e) Back to integer arrays of RGB
f) MemoryImageSource format
g) Back to the internel Java 'Image' class format

Thanks,

aero

[edit] typos [/edit]

[This message has been edited by aerosoul (edited 03-11-2002).]

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-11-2002 20:15

I just meant the specific ways the different formats that you intend to convert between are represented. Converting between Java class formats shouldn't be too hard because there should be APIs to accomplish that for you. It seems the only conversion you need to make is between the raw data format Java uses (integer array of RGB) and the format you need to perform your own transformation (float array).

Converting percentage-based representation of a greyscale image to a RGB is relatively simple. Assuming 256 values for each channel, white would be 255.255.255, and black would be 0.0.0. So basically you are mapping a percentage to a value between 0-255. That is easily accomplished by:

rgbVal = (int)percentage*255.

I still don't know how the 3 values are indicated in the array. If they are encoded in a single integer, then there is a couple ways it could be done. The most compact of which would be totalValue = (redVal << 6) + (greenVal << 3) + blueVal.

Going the other way is tougher, because if you start with a color image, then there is some relationship between the rgb values that determines the brightness value, but I wouldn't know offhand what that was.



-jiblet

aerosoul
Paranoid (IV) Inmate

From: Cell block #4
Insane since: Jun 2001

posted posted 03-12-2002 16:02

Thanks jiblet, I think I understand.

I need a little more help with the color representation though.

I am not familiar with the '<<' operator - if it is an operator even, and was/am very confused when it comes to representing an RGB triplet as a single integer, going back and forth between those values and somehow extracting the 'brightness' out of it.

Any pointers?


InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-12-2002 16:59

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-12-2002 19:24

Jesus Ini, sorry I insulted you so badly. Yes, it was a presumptuous statement, yes, you should tell me I was wrong. I'm sorry I don't participate here more often so that I know everyone's areas of expertise. I am not dismissing your work, I am UNFAMILIAR with your work. However, "nobody on this board is capable" should not be in quotes because that's not what I said. Feel free to take issue with the opening 2 sentences, that was poor judgement on my part, but to say that my posts are often "senseless" and that I'm a "striving wannabe" and a "know it all" is at least as insulting to me as my ignorance of your experience is to you.

The only reason I try to help is because I don't think it's fair to just post questions without helping out where I can. If by 'striving wannabe' you mean inexperienced, then I fully agree with you. I am an interdisciplinary student (Math, Studio Art, CSCI) that is still in the thick of the CSCI portion. But keep in mind that I was trying to help with the MATHEMATICAL side of this problem. I clearly stated that I did not have the Java API knowledge to help with that portion of the problem. I don't see how that makes my words "senseless", or makes me a "know it all."

I am not here to "brag" or convince people how smart I am. I'll leave the judgement of my skills to my professors and employers. I value this community as a resource (even if I don't always have time to participate on a personal level), particularly because the maturity level is head and shoulders above your average message board. I would appreciate if you could point out where the false information that I often bring is so that I am aware of it. I know for a fact that from time to time I have brought solutions where (for whatever reason) no one else stepped up (eg), not to mention helping people understand difficult topics in my csci and math classes.

So, I apologize for being a dick, and if my words are truly as pointless as you make them out to be, then maybe I should stick to face-to-face communications from now on.

-jiblet

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-12-2002 19:30

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-12-2002 19:46

<< is bitwise left shift. All it does is move the bits in the operand that many positions to the left. Where I said (redVal << 6) + (greenVal << 3) the 6 and 3 should actually be 16 and 8.

IN relation to what InI just posted:

0xff << 8 == 0x0000ff00
0xff << 16 == 0x00ff0000

The reason is because every hex number is 4 bits.

0x8 = 1000
0xA = 1010 = 10
0xF = 1111 = 15

However, these are esoteric details to the Java programmer as InI made clear. I would just delete my posts, but now that I've opened my fat mouth I thought I needed to close loose ends.

[This message has been edited by jiblet (edited 03-12-2002).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-12-2002 19:53

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-12-2002 20:33

Reacting violently is better than not reacting at all, but worse than reacting level-headedly. See new post.

-jiblet

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-12-2002 21:11

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-12-2002 21:21

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

aerosoul
Paranoid (IV) Inmate

From: Cell block #4
Insane since: Jun 2001

posted posted 03-12-2002 21:37

Thanks a lot for the information, you guys. Still checking out some of the information InI posted.

To be honest though, after the lack of traffic on this thread, and my growing desperation, I spent some serious quality time with the API and Google last night. I went the way of creating a BufferedImage, because that seemed to work out the easiest for me, and provided direct random access to the pixels themselves. In fact, it was looking very promising, and I had gone so far as to produce the final integer array I needed to convert to an image and render - THAT was the hard part. I stil haven't figured it out, and couldn't decide between the MemoryImageSource approach, or the WritableRaster approach. Both of them involved ColorModel and SampleModel and other such classes that went over my head again. It boiled down to whichever I could get to work, which was ultimately neither. For this assignment however, I worked out a non-Java workaround that my professor approved, but I would still like to see what I can do about that for my own satisfaction. Going to check over your links right now InI..

Having said that however, thanks a lot for your help guys..

aero

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-12-2002 22:16

Oops, sorry it took so long to get the new thread started, got busy all of a sudden.

Anyway, I don't have anything further to add until I actually have time to sit down and try to develop an applet of my own. In my java class the focus was on OOP and common algorithms, and so we only touched on Applets long enough to understand how they work in the most basic way. All of our assignments were actually CLI apps. At any rate, I bet everything aerosoul needs is not in this thread somewhere.

Hope you're still around in 2 years after I graduate InI, then we can have real CG discussions.

-jiblet

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 03-12-2002 22:43

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

aerosoul
Paranoid (IV) Inmate

From: Cell block #4
Insane since: Jun 2001

posted posted 03-14-2002 01:48

Hey, you guys.

Although I sidestepped a lot of the problems I had with getting it to work 'ideally', I have a finished product. The Java part is really little more than a glorified image viewer, while the real workhorse is the Matlab function. More to the point, I got full credit for it

Here it is in all it's fake wannabe glory: http://www.prism.gatech.edu/~gte178z/mathEC/index.html

Thanks for all the help though...still going to try to tame Java, but not so urgently anymore

aero

« BackwardsOnwards »

Show Forum Drop Down Menu