NI Home > Community > NI Discussion Forums

LabVIEW

Showing results for 
Search instead for 
Do you mean 
Reply
Member
Chris S.
Posts: 48
0 Kudos

Load Jpeg and convert to 8 bit grayscale array?

Hi,
 
I am trying to load a jpeg image and convert it to a grayscale array (0-255 depth) but I am having an awful time.  I did this previously with the Vision evaluation module using image to array functions but I am trying to do it with the graphics pallette that is free.  Does anyone know where my problem lies?
 
I am loading the image with the Read Jpeg file.vi I selected use 8 bit color table and i then am using an unflatten pixmap to extract an array but clearly these values are not representative of the grayscale image pixel values (they seem like RGB Values).  I need the grayscale values so I can identify a dark edge by passing the array in a for loop and checking for a grayscale value.
 
So how do I upload a jpeg and convert it to a 8 bit greyscale array so I can get my edges?
 
Thanks for your help
 
Proven Zealot
MikeS81
Posts: 5,371
0 Kudos

Re: Load Jpeg and convert to 8 bit grayscale array?

Hi Chris,

to convert a RGB value to a grayscale value use this formula: "gray = 0.299R+0.587G+0.114B". To detect your edge see something like "Sobel-Operator", "Prewitt-Operator", or .... .

Mike

Member
Chris S.
Posts: 48
0 Kudos

Re: Load Jpeg and convert to 8 bit grayscale array?

Mike I am not sure how to use the gray level formula you provided all I have is an array of integers.

But here is some more clarification of what i am trying to do and have done because I read my previous post and it seemed confusing.  Sorry about that :smileywink: that was due to frustration.

I am loading and clipping a jpeg that is a monochrome image.  I want to turn this clipped image into an array that maps out the gray level (0-255) of each pixel in a 2 D array and I don't have IMAQ Image to Array function.  How would I do this with just the graphics palette included in the development edition of Labview?

I tried using the unflatten pixmap vi but the 8 bit output array is not what I am looking for the numbers are not 0-255 or seem to represent gray because it gives a color image when I display it.  How do I convert each number in the array to its 0-255 grayscale representation?  Attached are two pictures that show what I have.  As far as Identifying the edges I do have a vi that does this that I created from a program I made previously it just requires the grayscale 0-255 image array and thats what has me stressed :smileysad:.

Proven Zealot
MikeS81
Posts: 5,371
0 Kudos

Re: Load Jpeg and convert to 8 bit grayscale array?

Hi Chris S.,

here is an example for you. The formula is integrated. Hope it helps.

Mike

Active Participant
daveTW
Posts: 494

Re: Load Jpeg and convert to 8 bit grayscale array?

Hi Mike,
your VI didn't work for me, since the RGB- Values are packed in triplets. I changed your VI, now it works.
greets, Dave
Greets, Dave
Proven Zealot
MikeS81
Posts: 5,371
0 Kudos

Re: Load Jpeg and convert to 8 bit grayscale array?

Hi daveTW,

my vi work in this way i want. Because Chris only want a 2D Array of grayscale values.

Mike

Member
Chris S.
Posts: 48
0 Kudos

Re: Load Jpeg and convert to 8 bit grayscale array?

Wow Mike,
 
That was exactly what I was looking for.  I am very impressed and delighted that people like you take the time to help frustrated folks like myself.
 
Tremendous Thanks,
Chris
Member
Anfego
Posts: 8
0 Kudos

Re: Load Jpeg and convert to 8 bit grayscale array?

Hi all, Im having the same problem, but I cant open this examples because I have the version 7.1. If somebody can help me with it I'll appreciate.
Proven Zealot
MikeS81
Posts: 5,371
0 Kudos

Re: Load Jpeg and convert to 8 bit grayscale array?

[ Edited ]

Hi Anfego,

attached you will find a picture of the improved code.

Mike



Message Edited by MikeS81 on 07-22-2008 09:50 AM
Proven Zealot
muks
Posts: 7,208

Re: Load Jpeg and convert to 8 bit grayscale array?

Mike,
         Extracting a single plane should convert the jpeg image to a 8-bit grayscale image right?