LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Image (JPG) to 2D array

So what I want to do is load a JPEG, convert it to a 2D array of colors (grayscale or not, doesn't matter) - just so I can tell where an outline of a shape is.  Eventually I want to send the coordinates of the outline of the shape over serial, but I'm not quite there yet.

 

I know y'all don't like old revived threads, but I was using code that was found in an earlier thread that converts a JPEG to a 2D grayscale array and couldn't get it to work as I thought it would. When I try to open the attached jpg (untitled) in the attached vi, it only shows 29 rows of data in the 2D array which is not the whole picture.

 

I'm using the evaluation version of LabVIEW 2009 and have little to no experience in image processing, so forgive me if my vocab sounds like I'm a little (or a lot) lost.

Download All
0 Kudos
Message 1 of 10
(7,978 Views)

Hi,

 

If I understand correctly what you're trying to do is you want the a 2D array which is each pixel in an element. You won't get that from doing a straight conversion to a 2D array from Jpeg because the jpeg is compressed data, hence why you got only 29 rows of data and not the whole picture. From a bitmap to 2D array should give you what you need to look for the outline.

Another option is to use the vision module NI offers... there are very useful functions to do pretty much everything you could imagine in image processing.

 

Regards,

J

0 Kudos
Message 2 of 10
(7,971 Views)

Get rid of all the code in your lower part of the diagram and replace it with unflatten pixmap.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 3 of 10
(7,966 Views)

A direct "Image to array.vi" gives me this.

 

out.PNG

0 Kudos
Message 4 of 10
(7,960 Views)
img.PNG
0 Kudos
Message 5 of 10
(7,957 Views)

I don't think the OP has IMAQ, just plain LabVIEW.

 

Here's what I had in mind. Remember, that the image is 24 bit color, so you might want to split it into three arrays: R, G, and B. If the image is greyscale, all three contain the same info, so one (e.g. R) will suffice for processing.

 

Message Edited by altenbach on 11-20-2009 08:34 AM

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 6 of 10
(7,919 Views)

Alten, you're right. I only have plain LabVIEW. But the image will not always be grayscale, converting it to grayscale just helps me find the outline.  The problem with what I have is that I don't seem to have the whole picture so I'm wondering if what Jchec said is the problem.  Because it's a jpg will not get the whole picture? 

 

I've attached a screenshot of what I see, and the part circled in red makes me think I'm not seeing the bottom of the square (the <10 numbers is what I'm going to be looking for for as the outline). Everything goes to 0, which would indicate black?

0 Kudos
Message 7 of 10
(7,895 Views)
Thanks all, I think I got it to work.  I've moved on to figuring out how I'm going to creating the image->microcontroller interface.
0 Kudos
Message 8 of 10
(7,865 Views)

mosfetthepup wrote:

Because it's a jpg will not get the whole picture? 


Of course my method will get the full picture. That has nothing to do with jpeg compression.

 

The code in the original post has a problem in that N seems incorrectly calculated. (Try to divide by 3 instead of 8 at the Quotient&Remainder. :))


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 9 of 10
(7,861 Views)

The code in the original post has a problem in that N seems incorrectly calculated. (Try to divide by 3 instead of 8 at the Quotient&Remainder.

Yes, that's what I caught. >_<

0 Kudos
Message 10 of 10
(7,850 Views)