Hi guys,
I've asked for help here once before with great results, I thought I'd try it again.
(I'm on Ubuntu 6.06 with python 2.4. Xemacs as editor.)
I have an image as a scipy array and I've made a mask array for it, sources (stars/galaxies/etc.) are flagged with 1, sky is 0. Now I want to blow up the size of each flagged source by a factor of 2, or close to it. Meaning, if I originally have - array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
-
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
-
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
-
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
-
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
I want to have -
array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
Now, I thought wrong, and instead I wrote something that simply takes each pixel flagged with '1' and adds the indices of all its neighbouring pixels to the mask. But that only blows things up by one additional pixel at the borders of the source. Really not what I wanted. However, I could use the same technique if I knew the radius of each flagged "island" (at least approximately. and it will be different for every source). But it seems to me I'll have to got throught the image line by line to obtain the max and min indices of each group of neighbouring pixels. That would be incredibly slow, especially since I have over 3000 images (and many many things are being done to them, in addition to masking the sources).
I was wondering if you have some ideas. Maybe something like this already exists somewhere? Surely people have tried at some point to do exactly this, increase the masked area in an array by some factor??
Well, here's my code, it's looks really sad. -
import pyfits as PF
-
import scipy
-
import sets
-
-
def maskObjects(image):
#'image' is segmentation image from SExtractor -
fits=PF.open(image)
-
data=fits[0].data
-
hdr=fits[0].header
-
data=data.astype(float)
-
-
#for test purposes only
-
data=data[1000:1015,1000:1015]
-
-
#make mask, mark source with '1', sky with '0'
-
mask=scipy.where(data>0,1,0)
-
-
idx=[]
-
for i,value in enumerate(mask.flat):
-
if value: idx.append(i)
-
idx_array=scipy.array(idx)
-
width,height=idx_array.shape
-
-
-
-
left=sets.Set((idx_array-1).flat)
-
right=sets.Set((idx_array+1).flat)
-
low_left=sets.Set((idx_array-1+width).flat)
-
low_right=sets.Set((idx_array+1+width).flat)
-
up_left=sets.Set((idx_array-1-width).flat)
-
up_right=sets.Set((idx_array+1-width).flat)
-
orig_set=sets.Set(idx)
-
-
blownup=orig_set.update(left.update(right))
-
blownup.update(low_left.update(low_right))
-
blownup.update(up_left.update(up_right))
-
-
# remove indices out of bounds here. - Later.
-
#max_idx=width*height-1
-
-
3 2182
I see I made a typo in my code
width,height=id x_array.shape
should instead be
width,height=ma sk.shape
well, damn it all to hell!! My code doesn't even do what I thought it did, it doesn't increase the size of the masked area, instead it shifts the source twice! I don't get it, surely if a pixel has index x, then the pixel right under it would have index x+image_width??
See the original
this is the result of my "increased" masked area
I need coffee.
Well, in case anyone cares, the above can be done correctly by modifying this code I found in the SciPy Cookbook at scipy.org/Cookbook. Import scipy somewhere. -
def enlarge(a, x=2, y=None):
-
"""Enlarges 2D image array a using simple pixel repetition in both dimensions.
-
Enlarges by factor x horizontally and factor y vertically.
-
If y is left as None, uses factor x for both dimensions."""
-
a = asarray(a)
-
assert a.ndim == 2
-
if y == None: y = x
-
for factor in (x, y):
-
assert factor.__class__ == int
-
assert factor > 0
- return a.repeat(y, axis=0).repeat(x, axis=1)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: matt |
last post by:
Hi, I have two pairs of image. In each pair there is one image that is
masked by the other. I have then attempted to overlay them. However,
the image that is being masked has white corners. How can I make these
corners transparent. An example is shown at
http://portcanal.co.uk/filter.html What I would like is for the
background to the yellow triangle pair to be transparent. How do I do
this?
Thanks.
|
by: Nick |
last post by:
I have found a class that compresses and uncompresses data but need
some help with how to use part of it below is the deflate method which
compresses the string that I pass in, this works OK. At the end of
this message is the inflate method this is where I get stuck I know
that I need a byte array but because I am decompressing a string I
have no idea of how big the byte array will need to be in the end (the
inflate and deflate methods...
|
by: orekinbck |
last post by:
Hi There
I have spent alot of time trying to get a masked text box to validate
e-mails, but with no success. Mainly because I can't figure out how to
account for the wide variety of different e-mail addresses, for
example:
billwallis@hta.com
bill.wallis@hta.com
billwallis@hta.com.au
bill.wallis@hta.com.au
|
by: Kostis |
last post by:
Hello there!
I have created a windows application in VB.NET and I want to retrieve
data from an access database. I create the OleDbConnection, an
OleDbAdapter, a dataset and finally a Data Form using the Data Form
Wizard. Everything works fine.
The problem is that I want to use the masked edit control to manage
the way some fields appear, and are being stored to the database.
I insert the "Microsoft Masked Edit Control, version 6.0" (Path...
|
by: Panos |
last post by:
Hi all,
I can't clear a Masked edit control. I use it to input dates, so I have
defined the mask as "##/##/####". I use the the well known
meb.mask=""
meb.text="" ,
but nothing happens.
Does anybody have a clue, why these lines don' t work? I use vb.net 2002
Thank u
| |
by: DazedAndConfused |
last post by:
Curently I manualy code keypress edits. i.e. allow only 3 digits before
decimal and two digits after decimal in .NET.
Is there an easy solution to mask text boxes?
The MSMASK32.OCX from vb6 does not seem to be appropriate for a desktop
application with textboxes not bound to a dataset, am I wrong?
--
How time fly's when you don't know what you are doing!
|
by: jean-michel bain-cornu |
last post by:
Hi all,
I'm trying to get the whole field selected when the caret arrives into a
wx masked control.
This is perfectly done with the program below.
But if I comment out the line "r= dlg.ShowModal()", I get something
different : the data within the field is no more correctly selected.
Why ? And is there any solution ?
If somebody have got an idea, I'd be delighted.
|
by: dmbuso |
last post by:
I have a money field defined in a SQL Server 05 database with a value of
49.50. Also, it displays in SQL Server as 49.5000. I have a form in VB.NET
2005 and I'm using the new MaskedTextBox control in Visual Studio. I set the
Mask property for the text box to "$999.00".
The problem is when I run the form the text box displays "$495.00" and not
"$49.50" as one would expect. It it shifting the values left here. How do I
fix this?
Thanks...
|
by: michels287 |
last post by:
I have a masked textbox on my form.
I have an onscreen keyboard with numbers only.
The masked format for the masked textbox is: (###) ### - ####
I want to make sure they enter the phone numbers properly, hence the mask.
What I cannot seem to figure out is why can I not send the button captions (captions are the value of the number buttons, 1 through 9) into the masked box without an error?
I get: Run Time Error '380'. Invalid...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |