473,692 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading an image pixel by pixel

HaLo2FrEeEk
404 Contributor
I'm trying to create a QRCode decoder in PHP. I'm not sure if something like this has been created already, but from my searching, I don't think it has. If you don't know what QRCodes are, they're basically 2D barcodes that let you store a lot of information. Here's an example:


(mouse over for the whole thing)

This code is simple, just contains the text "0123456789 ", but it's just for testing purposes.

I'm basically working my way up a QRCode generator script, doing everything in reverse. it's obviously possible to decode them, there are many barcode readers for mobile phones capable of doing it, and there's also this site:

http://zxing.org/w/decode.jspx

But the source for that web-based decoder isn't available, and I'd like to try and figure it out on my own.

Ok, so now that you know the context, here's what I'm doing. First, I read the image and get it's width and height, which should always be equal. I start at the top-left corner and work my way down 1 pixel at a time in a diagonal line until I find a pixel of a different color (the border is always white, but not always the same width.) Once I've found a different colored pixel, I know how wide my border is. Starting at the border offset, I again recurse down until I hit another white pixel, this gives me my block width (the width and height of each square in the image.) I then find the "smallsize" of the image, the size I have to make it so that each square is a single pixel, without the border. I then do an imagecopyresize d() to shrink the image down to it's smallest size, making each square a single pixel.

And this is where I'm stuck. I need to read the value of each of the pixels, BUT, I need to ignore some as well. The larger squares in the top-left and right, and bottom-left are positioning data, used to tell mobile scanners how to rotate the image to read it. I don't need their pixel data. Each of the positioning squares are 8x8. There are also lines of timing data. I'm not sure what it's for, but it's not part of the data and I don't need it's pixel value either. Here's another version of that same image above, but with the data pixels turned red:



The 3 8x8 squares in the corners and the black pixels apart from those need to be ignored. Basically what I'm doing now is I'm just iterating through every pixel, like this:

Expand|Select|Wrap|Line Numbers
  1. $x = 0;
  2. while($x < $smallsize) { // while x is less than 21
  3.   $y = 0;
  4.   while($y < $smallsize) { // while y is less than 21
  5.     $vals[$x][$y] = imagecolorat($shrink, $x, $y);
  6.     $y++;
  7.     }
  8.   $x++;
  9.   }
And that gives me an array or each pixel's on/off value. So since Idon't need the positioning and timing pixels, how would I go about ignoring them?
Jun 3 '10 #1
2 4706
code green
1,726 Recognized Expert Top Contributor
I think I understand. I have done similar image mapping in C.
I found when reading picture files the beginning of the files would contain so many bytes of non-picture data -
size, dimensions date etc.
This info data can quite easily be ignored if you know where it will be and how many bytes long it is.

I am guessing in your case it will vary.
but what I am getting at is does this positioning data follow any regular pattern (no pun intended).
Is it always in the same place?
Is it always the same size?
Does it have a start of positioning data flag?
The picture data will be all integers.
Are there other ASCII characters in the positioning data?
Jun 4 '10 #2
HaLo2FrEeEk
404 Contributor
Misunderstandin g. These sort of images are meant to be read optically, by a barcode scanner, not as an actual file. Attached is another image where I've highlighted the pixels that are not supposed to be read (at least by my scanner, they DO need to be read, but I don't need them yet.)

So basically I need to ignore any of the pixels that are highlighted red, and read the rest of them. I don't need their actual color value, just if they're on or off (white or black).
Attached Images
 
Jun 4 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6280
by: Will McGugan | last post by:
Hi, I'm writing an app that downloads images. It rejects images that are under a certain size - whithout downloading them completely. I've implemented this using PIL, by downloading the first K and trying to create a PIL image with it. PIL raises an exception because the file is incomplete, but the image object is initialised with the image dimensions, which is what I need. It actualy works well enough, but I'm concerened about...
0
1330
by: Thomas | last post by:
Hi all, I'm in search of a fast solution to reading image dimensions. I know you can get the image dimensions by loading a file into an image object, and then reading the height/width properties, but this is really slow (relatively speaking). Another poster suggested I could read the image headers manually by streaming the first X number of bytes of the file, but this is fairly consuming approach and hoping there's another option.
3
2297
by: Steve Tooke | last post by:
I'm trying to find a way to quickly read image headers (specifically jpgs at the moment) with out loading the whole image as an System.Imaging.Image. Anybody point me in the right direction or am I going to need to write a header parser from scratch?
4
8220
by: grogerteal | last post by:
Hello, I am pretty new to programming and would like someone to help me get started on the program that I need to make. I hope it is not hard to do, but what I would like is a simple app that has a label which returns the color of a pixel that is in position x,y on the screen (i.e. the desktop @ 1024 x 768 pixels), where x and y are of course variable.
4
7616
by: Andy | last post by:
Hello All: I have a field in the database that is an Image. I have no idea how the data is stored in here (Image, compressed, encrypted, plain text, etc). I am trying to write the contents to a text file, image file, etc so I can see if the data is stored in a way we can understand (we have been tasked to write an app and the app needs to read this field, but we don't know what it really contains). How would I go about reading the...
2
3749
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image. At least when I execute the following code, I get some significant network traffic. When I check the database with query analyzer, I see 4 Hex Chars in the image colum. Like 0xe0 etc.
1
5611
by: Akhilesh Upadhyay | last post by:
Hello Friends. I need C or C++ code for Image to Pixel matrix conversion. I have an image & I want to read all its pixel values. If you have such code please email me the code. Thanks, Akhilesh Upadhyay
0
1005
Zerin
by: Zerin | last post by:
Guys, Anyone has any idea about how to determine the start points and end points to draw a rectangle if I have two points for (x1,y1) thats the left top point's co-ordinate and (x2,y2) as the right-bottom point of a rectangle? I guess it has to be converted to pixel. Actually,I have to draw rectangle from a garber data file and it has the above value of x1,x2,y1,y2 and I have to draw rectangles according to that file. Can anyone help?
2
7379
by: Ed | last post by:
Hope someone can help me out... I have been tasked to read some image data from an sql database and save the files to flat files. OK, sounds easy as I'v used BLOBs before. But this is an old database and I cannot get the image to work. The columns in the database are of type text. Here is one of the images text (in full) in the database (I hope you can see it):
1
413
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties are set using Reflection
0
9090
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8970
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8812
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6462
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5822
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4564
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2242
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1962
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.