473,769 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scale a vector

Hi!

I've to scale a vector of numbers of size N to a vector of size M.
The trasformation is like a zoom on images but I need on a vector.

The second size can be M >= N or M <= N, M 0.

The value for each element can be from 0 to 255.

Is there some methods that can I use?

I don't need only a resize.

Thx! ;-)
Matteo Migliore.
Sep 16 '07 #1
19 4897
Matteo Migliore wrote:
Hi!

I've to scale a vector of numbers of size N to a vector of size M.
The trasformation is like a zoom on images but I need on a vector.
I'm not really clear on the exact meaning of your description; is "N"
and "M" the magnitude of the vector? Do you already know those values,
or do they need to be calculated as well? How many dimensions does the
vector have?

Anyway, it seems to me that if you're just doing scaling, it would be
easiest to just write a simple method that does the work.

However, there is a Matrix class; if you already know M and N, and your
vector is a 2-dimensional vector, you could initialize a Matrix instance
with the scaling factor of M/N along the diagonal and then use the
Matrix.Transfor mVectors() method to scale your vector.

If the above doesn't help, maybe you could be more specific.

Pete
Sep 16 '07 #2
Peter Duniho wrote:
Matteo Migliore wrote:
>Hi!

I've to scale a vector of numbers of size N to a vector of size M.
The trasformation is like a zoom on images but I need on a vector.

I'm not really clear on the exact meaning of your description; is "N"
and "M" the magnitude of the vector? Do you already know those
values, or do they need to be calculated as well? How many
dimensions does the vector have?
N is the size of the vector, M is the wanted size after the processing
of the new vector.

With vector I intend an array of int: int[] vector = new int[] { 10, 15, 17,
30, 200 };

In this case N = 5 and for example I need a new vector of size 8 that
redistributes
the values. Think that is a line:
P1(1, 10) - P2(2, 15) - P3(3, 17) - P4(4, 30) - P5(5, 200)

I need a new line:
P1(1, ?) - P2(2, ?) - P3(3, ?) - P4(4, ?) - P5(5, ?) - P6(6, ?) - P7(7, ?) -
P8(8, ?)

Or a new vector of 4 elements, or 3 etc...
Anyway, it seems to me that if you're just doing scaling, it would be
easiest to just write a simple method that does the work.

However, there is a Matrix class; if you already know M and N, and
your vector is a 2-dimensional vector, you could initialize a Matrix
instance with the scaling factor of M/N along the diagonal and then
use the Matrix.Transfor mVectors() method to scale your vector.
No, it's not a 2-dimensional vector, it's a 1-dimension vector. But can I
use Matrix.Transfor mVectors() .
If the above doesn't help, maybe you could be more specific.

Pete
Thx a lot! ;-)
Matteo Migliore.

Sep 16 '07 #3
Matteo Migliore wrote:
N is the size of the vector, M is the wanted size after the processing
of the new vector.
IMHO, we are having some problems with your terminology. For example:
With vector I intend an array of int: int[] vector = new int[] { 10, 15,
17, 30, 200 };

In this case N = 5 and for example I need a new vector of size 8 that
redistributes the values.
Based on the above statement, M and N are the _dimensions_ of your
vectors. Assuming you want to continue calling the two arrays vectors,
of course.
Think that is a line:
P1(1, 10) - P2(2, 15) - P3(3, 17) - P4(4, 30) - P5(5, 200)
That's not a line. It's a bunch of lines, approximating a curve.
I need a new line:
P1(1, ?) - P2(2, ?) - P3(3, ?) - P4(4, ?) - P5(5, ?) - P6(6, ?) - P7(7,
?) - P8(8, ?)
If you're treating the "vector" as a collection of second coordinates in
a 2-dimensional space (which is what the above implies), why are you not
adjusting the first coordinate in the output sequence as well?

For example, if your original "line" starts at (1, 10) and ends at (5,
200) wouldn't you also want the resulting "line" to also start at (1,
10) and end at (5, 200)?

As far as the specific example goes, what would those "?" be replaced
with? Do you have a specific relationship between the input and output
data in mind? Or is part of your question intended to solicit opinions
regarding what an appropriate relationship would be?
[...]
No, it's not a 2-dimensional vector, it's a 1-dimension vector. But can
I use Matrix.Transfor mVectors() .
You cannot use TransformVector s(), of that much I am sure.

As for what the data is, it appears to me that it's not a 2-dimensional
vector, nor is it a 1-dimensional vector. The data is a 1-dimensional
array, which _possibly_ could be treated as an M-dimensional vector but
in fact it doesn't really appear to me that your data really is a vector
after all.

As for specifically how to "scale" the input data to create the desired
output data, I'm afraid I still don't see enough information to explain
what the intended results are. It seems that if you could provide at
least one concrete example of both the input and the output, that would
go a long way toward helping explain the problem better.

Pete
Sep 16 '07 #4
Peter Duniho wrote:
Matteo Migliore wrote:
>N is the size of the vector, M is the wanted size after the
processing of the new vector.

IMHO, we are having some problems with your terminology. For example:
You're right my teminology is wrong :-).
Sorry! :-P
>With vector I intend an array of int: int[] vector = new int[] { 10,
15, 17, 30, 200 };

In this case N = 5 and for example I need a new vector of size 8 that
redistribute s the values.

Based on the above statement, M and N are the _dimensions_ of your
vectors. Assuming you want to continue calling the two arrays
vectors, of course.
>Think that is a line:
P1(1, 10) - P2(2, 15) - P3(3, 17) - P4(4, 30) - P5(5, 200)

That's not a line. It's a bunch of lines, approximating a curve.
You're right again, suppose that it's a curve.
>I need a new line:
P1(1, ?) - P2(2, ?) - P3(3, ?) - P4(4, ?) - P5(5, ?) - P6(6, ?) -
P7(7, ?) - P8(8, ?)

If you're treating the "vector" as a collection of second coordinates
in a 2-dimensional space (which is what the above implies), why are
you not adjusting the first coordinate in the output sequence as well?

For example, if your original "line" starts at (1, 10) and ends at (5,
200) wouldn't you also want the resulting "line" to also start at (1,
10) and end at (5, 200)?
No, it's not a closed curve. It's only an array of int that I need to scale
to a less or great array. Think that the array are Y-coordinates and you've
to zoom (increasing or decreasing the size) of this curve.
As far as the specific example goes, what would those "?" be replaced
with? Do you have a specific relationship between the input and
output data in mind? Or is part of your question intended to solicit
opinions regarding what an appropriate relationship would be?
Mmmm I post a prototype of function that I need:
------------------------------
public int[] Scale(int[] array, int newSize) {
if (array.Lenght <= 3)
return array;

//Otherwise calculate the new values
int[] scaled = new int[newSize];

//Here is the problem! :-)
}
------------------------------

I've to preserve the curve "morphology ".
>[...]
No, it's not a 2-dimensional vector, it's a 1-dimension vector. But
can I use Matrix.Transfor mVectors() .

You cannot use TransformVector s(), of that much I am sure.

As for what the data is, it appears to me that it's not a
2-dimensional vector, nor is it a 1-dimensional vector. The data is
a 1-dimensional array, which _possibly_ could be treated as an
M-dimensional vector but in fact it doesn't really appear to me that
your data really is a vector after all.
My data are not real! I've to calculate from a real image before (read
down...).
As for specifically how to "scale" the input data to create the
desired output data, I'm afraid I still don't see enough information
to explain what the intended results are. It seems that if you could
provide at least one concrete example of both the input and the
output, that would go a long way toward helping explain the problem
better.
In pratical I need to resize RGB projections (horizontal and vertical)
of images from XxY to a TxZ, where T and Z must be fixed.

A RGB projection it's only a int[] array, the lentgh is X for horizontal
and Y for vertical projections. The range of values of elements of the
arrays is 0..255 (the luminance).

I hope to be more clear, sorry for my english :-).
Pete
Thx!!!!!! ;-)
Matteo Migliore.

Sep 16 '07 #5
Matteo Migliore wrote:
[...]
>For example, if your original "line" starts at (1, 10) and ends at (5,
200) wouldn't you also want the resulting "line" to also start at (1,
10) and end at (5, 200)?

No, it's not a closed curve. It's only an array of int that I need to scale
to a less or great array. Think that the array are Y-coordinates and you've
to zoom (increasing or decreasing the size) of this curve.
I'm not saying it's a closed curve. I'm trying to establish what the
input and output data look like. Preserving the end-points (1,10 and
(5,200) (using your previous "sample" data) doesn't close the curve. It
just anchors it in the same geographical location it previously had.

As far as "zoom" goes...typicall y that's implemented by just scaling the
entire input. If you've got 2-D data ((x,y) coordinate pairs), you
simply apply the same scale factor to both the x and y component;
there's not any specific need to create or remove data points.

In some situations, it's desirable to "smooth" out the zooming when
increasing the size by adding new points, or to enhance efficiency when
decreasing the size by removing points. Are you trying to do this? If
so, are you _also_ scaling the coordinates as well, or is this really
just an exercise in smoothing/roughening the original curve?
Mmmm I post a prototype of function that I need:
------------------------------
public int[] Scale(int[] array, int newSize) {
if (array.Lenght <= 3)
return array;

//Otherwise calculate the new values
int[] scaled = new int[newSize];

//Here is the problem! :-)
}
------------------------------

I've to preserve the curve "morphology ".
In the above function, why do you ignore the "newSize" parameter if the
input array is shorter than 3 elements? Why is it acceptable for the
method to return an array of a different size than requested? And if
this is acceptable, can that be taken advantange of in the more general
solution? That is, is it acceptable in other situations for the method
to return an array of a length different than asked for?
[...]
>As for specifically how to "scale" the input data to create the
desired output data, I'm afraid I still don't see enough information
to explain what the intended results are. It seems that if you could
provide at least one concrete example of both the input and the
output, that would go a long way toward helping explain the problem
better.

In pratical I need to resize RGB projections (horizontal and vertical)
of images from XxY to a TxZ, where T and Z must be fixed.
Whether the data you posted are real or not, it would still be useful to
have an example of data that reflect the complete algorithm you're
looking for. So far, all you've shown is a hypothetical input array;
without seeing a corresponding hypothetical output array, it's very
difficult to visualize what exactly you're trying to do.

Pete
Sep 16 '07 #6
Whether the data you posted are real or not, it would still be useful
to have an example of data that reflect the complete algorithm you're
looking for. So far, all you've shown is a hypothetical input array;
without seeing a corresponding hypothetical output array, it's very
difficult to visualize what exactly you're trying to do.
Mmm, it's hard for me to explain in a post what I need.

The algorithm that I've to develop simply create an array of Z elements
from an array of T elements, preserving the curve morphology.

I obtain the array processing an image.

I calculate the horizontal RGB projection and I need to scale
it to a fixed size array. The originally array size is the width of the
image.

I need to compare the RGB project of an image to another, but the resolution
of images can be different, so I've to build fixed array size, to compare.

Clear now?

Thx!!!
Matteo Migliore.

Sep 16 '07 #7
Matteo Migliore wrote:
[...]
Clear now?
Nope, sorry. Like I said, you really should post an example of input
data and output data that would result. You can try to describe the
process until you're blue in the face, the fact is there's nothing so
useful as having a concrete example to talk about.

If you do not even know what the output data will look like, then IMHO
you should focus on that first, rather than some specific
implementation. But in that case, you will at least need to come up
with a more easily-undersood way of describing what your goals are.

In particular, while I understand the idea of "preserving the curve
morphology", since I don't know what the curve you're talking about is,
that still doesn't help me. The term "projection " may in fact describe
what you're doing, it's not being used in a way with which I'm familiar.
You should try to simplify your terminology, so that we don't need any
specialized knowledge of your application to comprehend what you're
trying to do.

We're not dumb people here, but we're not necessarily conversant in all
technical fields, and we're not psychic either. :)

Pete
Sep 16 '07 #8
Peter has tried to get you to elaborate the problem. It now sounds that you
are trying to do image processing, and either stretch or shrink an image
based on an aspect ratio. This is quite different than stretching a
one-dimensional array, or refinining/simplifying a cartesian polygon or curve
as I thought you initially might be going toward.

If you are working image processing, my understanding from collegues, is the
value of any new pixel is based on the value of many surrounding points, not
just the ones immediately next to it. When throwing away points, there is a
similar issue, for deciding which value to throw away. You might throw away
the important pixel.

"Matteo Migliore" wrote:
Whether the data you posted are real or not, it would still be useful
to have an example of data that reflect the complete algorithm you're
looking for. So far, all you've shown is a hypothetical input array;
without seeing a corresponding hypothetical output array, it's very
difficult to visualize what exactly you're trying to do.

Mmm, it's hard for me to explain in a post what I need.

The algorithm that I've to develop simply create an array of Z elements
from an array of T elements, preserving the curve morphology.

I obtain the array processing an image.

I calculate the horizontal RGB projection and I need to scale
it to a fixed size array. The originally array size is the width of the
image.

I need to compare the RGB project of an image to another, but the resolution
of images can be different, so I've to build fixed array size, to compare.

Clear now?

Thx!!!
Matteo Migliore.

Sep 16 '07 #9
Family Tree Mike wrote:
Peter has tried to get you to elaborate the problem. It now sounds
that you are trying to do image processing, and either stretch or
shrink an image based on an aspect ratio. This is quite different
than stretching a one-dimensional array, or refinining/simplifying a
cartesian polygon or curve as I thought you initially might be going
toward.
Yes, and i thank Peter tooooo much for his time! :-)

But no, I need to resize a one-dimensional array.
If you are working image processing, my understanding from collegues,
is the value of any new pixel is based on the value of many
surrounding points, not just the ones immediately next to it. When
throwing away points, there is a similar issue, for deciding which
value to throw away. You might throw away the important pixel.
Suppose that you have three images: 640x480, 800x600, 1024x768.
The image is the same but at different resolution.

Here is a method to calculate the RGB projections, horizontal project in
this case:
--------------------------
public unsafe int[] GetHorizontalRG BProjection(Bit map bitmap){

}

public int[] Scale(int[] array, int size){

}
--------------------------

This function calculate the middle luminance for each column (X coordinate)
in the image and return an array of middle luminances, so the array lenght
is the width of the image.

Same thing for the vertical projection, but the calculate is on rows!

Ok, now I've to compare horizontal RGB projection for image A, B and C.

The array lenght must be the same, so I've to scale RGB proj. of A to 100
elements,
RGB proj. of B to 100 elements and the same for C. 100 is random selected,
it could be 640
(the most minum width for an image). If the image width is smaller than
100px the function must
Scale the array to 640.

So at the end the code is:
----------------------------------
Bitmap a = ...; //640x480
Bitmap b = ...; //800x600
Bitmap c = ...; //1024x768
int[] horizontalRGBPr ojectionA = GetHorizontalRG BProjection(a); //array
lenght 640
int[] horizontalRGBPr ojectionB = GetHorizontalRG BProjection(b); //array
lenght 800
int[] horizontalRGBPr ojectionC = GetHorizontalRG BProjection(c); //array
lenght 1024

horizontalRGBPr ojectionA = Scale(horizonta lRGBProjectionA , 640); //array
lenght 640
horizontalRGBPr ojectionB = Scale(horizonta lRGBProjectionB , 640); //array
lenght 640
horizontalRGBPr ojectionC = Scale(horizonta lRGBProjectionC , 640); //array
lenght 640
----------------------------------

Now I can compare the arrays.

Thx!!
Matteo Migliore.

Sep 16 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3740
by: John Fouhy | last post by:
So I've got a horizontal scale widget in my GUI. When I click the mouse in the area to the right of the GUI, the scale advances by 1. 13 +-------------------------+ |<| X |>| +-------------------------+ || \/
4
6609
by: codecraig | last post by:
Hi, I am using Tkinter and I have a Label and a Scale. I want to update my label everytime the Scale value changes. What is the best way of doing this? Do i have to bind for every event type? Or is there some better way? If I do have to bind each type of event to the scale, what types occur for a Scale? Thanks.
5
316
by: Guess | last post by:
The situation is as follows: 1. I would like to serve a web page that takes considerable time to process. 2. While the page is processing, the client displays an appropriate wait message. What are the consequences of having this long processing page when there are many simultaneous requests from many clients for the same page (say 75+).
3
7295
by: John Bonds | last post by:
I'm looking for some sort of digital scale to integrate into .NET. Does anybody know of anything (like a postal scale) that attaches to USB, serial or whatever that comes with a DLL or an API that I could integrate into .NET? Thanks, John
3
7122
by: Jay Patel | last post by:
Hello, I need to write visual basic.net code to interface with a Mettler Toledo Shipping Scale that interfaces with a PC via USB or a serial port. I have seen example code on how to communicate via a serial connection (RS-232), but am not sure as the process if it is connected via USB. Is the USB port seen then as a COMM port, or is there a different type of connection a USB port creates that I would have to open? The scale will take as...
3
2031
by: Jerry Spence1 | last post by:
A very useful feature was added in 2.0 of .NET framework which was the scaling of a form and all the controls within it. This is really useful but I am finding very little information of how to use it. I have managed to implement it as follows: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim addSize As New SizeF(0.5F, 0.5F)
0
1493
by: TonyJ | last post by:
Hello! We have a pc running a form application. If I push some buttons in this application I want to send some commands to a scale which is connected to a specific IP address. When I sent a command I also receive an answer from the scale. I want to communicate with the scale using TCP or UDP. The commands that can be sent to the scale are very short about 3 to 5 characters.
2
6262
by: DaveD170 | last post by:
Hi everybody, I'm newbie in c# and I'm having trouble in creating an excel chart. I have vector of data that my program calculated. It's in the next format: X Y 0.1 100 0.2 90 0.3 80 etc.
22
3666
by: Jesse Burns | last post by:
I'm about to start working on my first large scale site (in my opinion) that will hopefully have 1000+ users a day. ok, this isn't on the google/facebook scale, but it's going to be have more hits than just family and friends. Either way, I'm planning on this site blowing up once I have enough of a feature set, so I'm concerned about performance and scalability in the long run. I've worked for a software company, but I've never...
0
9586
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, 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...
0
10043
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...
0
9861
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 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...
0
8869
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, 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...
1
7406
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
6672
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
5298
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
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2814
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.