How can I locate a particular pixel in an image? I need to find 'odd' pixels counts, which I can do but I don't know how to get that particular pixel ( if that makes sense): -
from PIL import Image
-
-
i = Image.open('Img.bmp')
-
for pixel in i.getdata():
-
if pixel [2] > 0:
-
print pixel
-
That will print out just the ones I want instead of every pixel count in the image and the results are like this:
(77, 0, 8)
(89, 0, 8)
(41, 0, 10)
(50, 0, 7)
(42, 0, 5)
(55, 0, 9)
(112, 0, 5)
(105, 0, 9)
So in this instance I would need the pixel positions of the 3rd numbers in the R,G,B lists.
6 12023 bvdet 2,851
Recognized Expert Moderator Specialist
I don't understand your question. You can determine a particular pixel with the getpixel((col,r ow)) method.
Let's say I have a red image that has 8 blue pixels scattered through out it. If I run the code so it prints out like above, it verifies that they were found, but I don't know how to 'locate' them or find their x,y positions in the image. I'm trying to google getpixel((col,r ow)), it seems that may be what I want I just don't know how to implement it.
bvdet 2,851
Recognized Expert Moderator Specialist
Set the upper and lower limits of the pixels you want to find. The following is geared toward red. - from PIL import Image
-
import operator
-
-
img = Image.open(r'D:\Miscellaneous\BVLogo.png')
-
-
# List the pixels having RGB values in defined range
-
-
upper = (255,50,50)
-
lower = (200,0,0)
-
-
output = []
-
-
for col in range(img.size[0]):
-
for row in range(img.size[1]):
-
pixel = img.getpixel((col,row))
-
if False not in map(operator.lt,lower,pixel) \
-
and False not in map(operator.gt,upper,pixel):
-
output.append((col,row))
-
-
for pixel in output:
-
print pixel
I've tried the suggested code but can't seem to get it to work. I even tried switching around the R,G,B values but still nothing. Here's an example image for what I'm using: http://img404.imageshack.us/img404/3418/10x.png
If I run this code on it: -
from PIL import Image
-
-
i = Image.open('10x.bmp') # I save image as a bmp
-
for pixel in i.getdata():
-
if pixel [2] > 0:
-
print pixel
-
I get 88 results, which is what I'm after but I now need their 'x' positions.
What would I be doing wrong with bvdet's code that it doesn't work for me?
bvdet 2,851
Recognized Expert Moderator Specialist
You are not using the code I suggested. In your case, you want the pixel positions that have "B" values greater than 0. - from PIL import Image
-
-
img = Image.open('10x.png')
-
output = []
-
for col in range(img.size[0]):
-
for row in range(img.size[1]):
-
pixel = img.getpixel((col,row))
-
if pixel[2] > 0:
-
output.append((col,row))
-
-
for pixel in output:
-
print pixel
-
- >>> len(output)
-
88
-
>>> img.getpixel((122,73))
-
(17, 0, 9)
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: LRW |
last post by:
http://gto.ie-studios.net/index.php
When you view the above site in IE, if the 1st of the three product
images is tall enough to push the cell down a couple of pixels, IE
somehow doesn't show that happening.
But if you look at it in Firefox you can see the small gap of white
where the semi-circle image is broken.
I've tried changing...
|
by: hikums |
last post by:
how can I use a function inside a function, for example I want to
select col1, col2 from table1 where locate(dayofweek(current
date),col3) =dayofweek(current date)
col3 is a field that contains a string like '12 4567', or
'1 4567'. This field specifies what day in the week the job executes,
and if there is a match, I want to report col1 and...
|
by: Craig Parsons |
last post by:
Folks,
I have an image of a circle, which I am trying to straighten out into a
flat line. I am essentially wanting to look at the image, and read a
straight line from the centre, and then plot this on a graph. Then I want
to rotate the image 1 degree and read the next line down, if you see what I
mean.
My question is, how do I...
|
by: Stacey |
last post by:
I've been trying for the last couple of days to read some pixel values
from a window of an independent application, but, even though I got
close, I just can't figure the last part out.
I am able to read the coordinates (GetWindowRect), but the GetPixel
always returns some weird incremental value. Is there something wrong
with my...
|
by: David Wake |
last post by:
I am a complete Javscript newbie trying to produce a user interface
similar to Google Maps -- the user should be able to click anywhere on
the map and drag it in any direction.
The Javascript works OK when the map is only dragged a few pixels. If
the map is dragged any significant distance, however, the cursor
changes to a document-like...
| |
by: Jaap Bos |
last post by:
In VB2005 I use a rectangle (50,50,910,600) into which to display my
graphics.
After graphing my X-Y data I want to do some measurements on that curve
using a crosshair cursor.
So I a made a MouseDoubleClick event with the following code:
Dim position as Point
position=Control.MousePostion
tijd=position.X
|
by: 4.spam |
last post by:
Hello.
v8.2.1
Try this (and any 3-d argument):
---
select locate('','string',5) from sysibm.sysdummy1;
---
Is it a feature or a bug?
Sincerely,
|
by: Marcel Brekelmans |
last post by:
Hello,
I save and restore the position and dimensions of a form using
'this.DeskTopBounds'. However, every time I open the form its Height grows
with 19 or so pixels! Is there something I should subtract from the
DeskTopBounds Rectangle's Height value?
Thanks,
Marcel
|
by: Kevin Killion |
last post by:
I am building a website for a school, but running into a display problem
between IE and CSS. (The site is http://stmary-stthomas.org/ )
The main horizontal menu bar looks just fine on Mac and PC with most
browsers.
But on the PC with IE7, the menu bar winds up about 20 pixels too high.
The menu is drawn in a DIV with class "navbar",...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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. ...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
|
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...
|
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...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |