473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Why does if else statement always return if code even when failed?

8
The problem is that the "if-else" command doesn't work properly. the program always returns entire "else" commands means all black pixels in end.bmp . but there is some pixels that have the same values "(224 238 223)" in "model1.jpg".
thanks for your help.


Code :
Expand|Select|Wrap|Line Numbers
  1. import Image
  2. model1 = Image.open("model1.jpg")
  3. test = Image.open("test.jpg")
  4. im  = Image.new("RGB",(500,500))
  5.  
  6. rr1=224
  7. gg1=238
  8. bb1=223
  9.  
  10. for i in range(500):
  11.  for j in range(500):
  12.  
  13.   rtest,gtest,btest=test.getpixel((i,j))
  14.   r1,g1,b1=model1.getpixel((i,j))
  15.  
  16.   if r1==rr1 & g1==gg1 & b1==bb1:
  17.    realtestr=rtest
  18.    realtestg=gtest
  19.    realtestb=btest
  20.   else:
  21.    realtestr=0
  22.    realtestg=0
  23.    realtestb=0
  24.   im.putpixel((i,j),(realtestr,realtestg,realtestb)),
  25.  
  26. im.save('end.bmp')
  27. im.show()
  28.  
Feb 4 '11 #1

✓ answered by bvdet

Don't use the bitwise and operator & - use and. The & operator takes precedence over == and == takes precedence over and.

1 1685
bvdet
2,851 Expert Mod 2GB
Don't use the bitwise and operator & - use and. The & operator takes precedence over == and == takes precedence over and.
Feb 4 '11 #2

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

Similar topics

4
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want...
10
by: george young | last post by:
I had developed the habit of using the neat python form: if someinstance: someinstance.memb() because it seems cleaner than "if someinstance is not None". {please no flames about "is not None"...
0
by: Emmett | last post by:
The transform below should create a dropdown where the entry for "SSS Building I" is selected. (Or am I missing something? ) This transform creates the dropdown but doesn't do the select. Can...
5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
10
by: qazmlp | last post by:
There are some blocks of C/C++ code put under #if 0 #end if Is there anyway to make the code inside these blocks to get executed (may be by using some command line options)?
1
by: Rajeshwar_ts | last post by:
Hi, I am new to this group and new to PostGreSql. i am changing from MySql to PostGresql. I am unable to work with "Drop table if exists tablename" query. Is there any alternate query for...
0
by: eyalhz | last post by:
I have this code at button click: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ListBox1.SelectedIndex() Then Dim lines As...
6
by: vl106 | last post by:
A static code analysis tool gave me a warning on if (ptr && ptr->data) { ... } I assumed the tool doesn't get the "short circuit behaviour" in the if statement. But a collegue said it may...
1
by: MichaelZ | last post by:
After all is done, I want query(s) which will give me the ability to create a report which will allow me to compare 3 apts with the parameters equaling bedroom size, and rents which are equal or...
18
by: desktop | last post by:
I have 3 types of objects: bob1, bob2 and bob3. Each object is identified by a unique ID which gets returned by the function getId(). All bobs are descendants from class BaseBob which is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
tracyyun
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...
0
agi2029
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,...
0
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...

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.