C/C++ :: Two Dimensional Array Median Filtering?

Nov 12, 2014

I'm trying to write code that implements [median filtering] on a two-dimensional array.

Here's an image to illustrate:

The program starts at the beginning of the array. The maximum array size is 100. I know that I can use an array like:

int a[100][100];

to store the input, and that I can iterate over a part of this array using two `for` loops like this:

for(i=0;i<size_filter;i++)
for(j=0;j<size_filter;j++)
temp[i][j]=a[i][j] // not so sure

But how can I make this code loop over the neighbors of every element in the array, calculate their median, and replace the center element with the median?

For some examples of what I'm trying to do, let's say that the input is a 5x5 matrix, so the input size is 5. And I want to run a 3x3 median filter on it, i.e. each element should be replaced by the median of the 3x3 elements surrounding it.

The program starts at the corner index (0,0). For this index, it scans the 3x3 region surrounding it (of which only four indexes actually lie within the input array), which contains the values 0, 0, 1, and 0. The median of these values is 0, so that's what the code should output for this array index.

In the picture below, the number in -band - is the center cell, and the plain * and * numbers are its neighbors within the 3x3 region surrounding it:

-0- *0* 0 0 0
*1* *0* 0 1 0
1 1 0 0 0
0 1 1 0 0
0 0 0 0 0

Here's another example, this time with the center index (0,1):

*0* -0- *0* 0 0
*1* *0* *0* 1 0
1 1 0 0 0
0 1 1 0 0
0 0 0 0 0

This time, the elements in the 3x3 region (excluding those outside the input array) have the values 0, 0, 0, 1, 0, and 0, and again, their median is therefore 0.

Here's yet another example, this time from the middle of the input, at center index (3,2):

0 0 0 0 0
*1* *0* *0* 1 0
*1* -1- *0* 0 0
*0* *1* *1* 0 0
0 0 0 0 0

This time, the elements within the 3x3 region have the values 1, 0, 0, 1, 1, 0, 0, 1, and 1, and their median in therefore 1.

Final example:

<size of array><size filter> <data>
8
3
0 0 0 0 0 0 0 0
0 5 0 0 6 0 0 0
0 0 0 0 0 7 0 0
0 0 0 0 5 0 0 0
0 0 0 5 6 0 0 0
0 0 8 5 5 0 0 0
0 0 0 7 0 0 9 0
0 0 0 0 0 0 0 0

Output:

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 5 5 0 0 0
0 0 0 5 5 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

View 4 Replies


ADVERTISEMENT

C++ :: Passing 2 Dimensional Array Through Median Function To One Of 2 Other Function

Aug 20, 2013

I want to use one median function "selectfunction" to choose one of the 2 other functions at random to pass my 2-dim array to the selected function. There is a problem in the median function

#include <iostream>
#define random(x)(rand()%x) // for random number between numbers of 0 and 1
using namespace std;
void proc1 (int iArray[][2]);
void proc2 (int iArray[][2]);
void selectfunction(int iArray[][2]);
int A[4][2] = {{1, 2} , {3, 4} , { 5, 7} , {8, 1} };

[Code]...

View 1 Replies View Related

C++ :: Concatenate Two 2-dimensional Int Arrays Into One Larger 3-dimensional Array

Jul 31, 2013

How can I concatenate two 2-dimensional int arrays into one larger 3-dimensional array. This question is also valid for the 3-dimensional vectors. I know the command for the one dimensional vector as:

std::vector<int> results;
results.reserve(arr1.size() + arr2.size());
results.insert(results.end(), arr1.begin(), arr1.end());
results.insert(results.end(), arr2.begin(), arr2.end());

and for the one dimensional array as:

int * result = new int[size1 + size2];
copy(arr1, arr1 + size1, result);
copy(arr2, arr2 + size2, result + size1);

But I do not know how to make a 3-dimensional array or vector.

View 3 Replies View Related

C++ :: Find Median Of Array?

Jul 4, 2013

I am trying to find the median of an array in c++.

This is the array that I would like to find the median for.

scores[14] = {62,70,98,71,81,99,74,80,73,88,73,72,95,71};

View 5 Replies View Related

C++ :: Calculate Mode / Mean And Median Of Array Of Integers

Mar 17, 2013

I'm writing a program that calculates the mode, mean and median of an array of integers. I've done the mean and median but i can't figure out mode.

I have to find the number of modes.

Ex array of integers: 10, 10, 4, 5, 6,5, 6, 7

My function has to return the number 3. Because there are 3 sets of mode; 10,5,6.

How do i implement this in my function because for now it just calculates the mode. It only return the number mode 10.

View 5 Replies View Related

C/C++ :: Find Minimum - Getting Median And Mode In Array

Feb 7, 2015

So I am trying to find the min, max, range, mean, median, and mode. The max number is right but the min isnt. Once that is corrected, i can get range and mean easily. Also, how to get mode and median. I am guessing the values in the arr2 would have to be sorted. This refers to the values in arr2 which are the calculated values in the formula. You can enter -2 and 2 for userMin and userMax.

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
cout << fixed << setprecision(1);
float userMin;

[Code] .....

View 13 Replies View Related

C++ :: Create Program That Displays Median Of Array Using Pointers

Feb 27, 2013

The assignment is to create a program that displays the median of an array using pointers. Assume the array is already in ascending or descending order.I'm getting errors currently on the bottom two "return median;" statements.The code that I have so far is as follows...

#include <iostream>
using namespace std;
char again;
int getMedian(int*, int);
const int constant = 100;

[code]....

View 3 Replies View Related

C++ :: Converting One-dimensional To Two-dimensional Array

Jan 17, 2014

I had a hard question in my C++ final exam and I'm trying to solve it for the last 3 days. I haven't succeded yet! Here is the question: You have a one-dimensional array A[20]={1,2,3,4,...,20} and B[5][4] you have to assign the A array's elements to the B array but there is an order which is: B[5][4] = { { 12, 9, 11, 10 }, { 14, 7, 13, 8 }, { 16, 5, 15, 6 }, { 18, 3, 17, 4 }, { 20, 1, 19, 2 } } and there is a restriction: you can only use ONE for statement, nothing else!

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int A[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20 }; // define A array's elements.
int B[5][4] = { 0 }, k = 1; // define B array and k counter.

[code]....

I can't narrow the statements to one,This program works perfectly but it shouldn't be that long, we need ONLY ONE FOR statement, not two!

View 2 Replies View Related

C/C++ :: Find Median Of Array Of 5 Values - No Instance Of Overloaded Function

Mar 12, 2014

I am so close to finishing this program. It will find the median of an array of 5 values. I have one last error that I cannot seem to get to go away. Here's the code:

#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
using namespace std;
int main() {
int integer1, integer2, integer3, integer4, integer5;

[Code] .....

The error states: "IntelliSense: no instance of overloaded function "std::nth_element" matches the argument list, argument types are: (std::_Array_iterator, std::_Array_iterator, unsigned int, std::_Array_iterator)

View 1 Replies View Related

C++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

C :: Assigning One Dimensional Array To Two Dimensional Array

Mar 19, 2014

is it allowed to to like this:

char a[10] = "Lizard";
char b[2][5];
b[0][0] = a[0];
b[0][1] = a[1]; etc?

View 1 Replies View Related

C :: How To Copy 3 Dimensional Array Into 2 Dimensional Array

Sep 2, 2013

I have a 3D array that contains 200 strings. I'm trying to copy all these strings into a 2D array. How can this be done? This is what I have so far but it isn't working correctly.

Code:
for(int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
{
dest[i][j] = source[0][i][j];
} }

The finished product would be with 100 rows, 2 columns.

View 4 Replies View Related

C :: Converting One Dimensional Array To Two Dimensional Array

Aug 30, 2013

convert an one dimensional array into a two dimensional array and print like a matrix.

input: 34 50 2 4 90 33 7 80 9
output: A is a 3x3 matrix
34 50 2
4 90 33
7 80 9

View 12 Replies View Related

C :: WAV File Handling And Filtering

Dec 29, 2013

I got this issue to tackle which consists of using an FIR LPF filter to filter a wav file using C programming.

Till now I managed to tackle the filter part following this link: Implementation of FIR Filtering in C (Part 1) | Shawn's DSP Tutorials (I have my own filter co-efficients which have been produced using FDAtool on MATLAB and some other minor changes have been applied to match my requirements)

Now, the link shown does not compensate for files having a header. I have three wav files which need to be filtered. Thus I need to first extract the data from the header .. this was done using RIFFpad. Now that I have the data

Info from RIFFpad:
fmt -
Offset=20
ID=fmt

[Code].....

I've got this hint to start with: Each audio datasample inside the wav_files can be made up of a number of bytes and these bytes arestored in the little-endian order. Inside your program you have to change this to a big-endian order.

View 8 Replies View Related

C# :: Filtering Strings That Get Sent On A Event

Feb 4, 2015

I am writing a application that receives Event messages from a network device the problem I have is that the device sends some message 5 times per tiggered event on two of the events I like to use the rest of the messages are fine I need to create code to filter out the other 4 last messages that get displayed in a textbox the 5 message are identical I have added a timestamp to the sting and noted they are always 1 second apart so the format would be somthing like this:

11:23:01 - x - y
11:23:02 - x - y
11:23:03 - x - y
11:23:04 - x - y
11:23:05 - x - y

What I would like to do something like this, always append the first message to the textbox but ignore or even change the 4 messages that follow 1 second apart from each other that contain - x - y if any other message appears it should still append the text box as well

so the result i would like for the 5 event message as above should end like this:

11:23:01 - x - y
11:23:02 - custome message / ingnore append to textbox
11:23:03 - custome message / ingnore append to textbox
11:23:04 - custome message / ingnore append to textbox
11:23:05 - custome message / ingnore append to textbox

View 8 Replies View Related

C# :: Why Filtering In Data Grid Don't Work

Oct 8, 2014

why filtering don't work??

This is code for load data into dataGridView

private void Izvestaj_Load(object sender, EventArgs e) {
connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:UsersTomyDesktopzadatak2zadatak2fedek_OldVersion(2002-2003).mdb;User Id=admin;Password=;";
dt = new DataTable();
OleDbDataAdapter sda = new OleDbDataAdapter("SELECT korisnici.korisnik,dogadjaji.dogadjaj,Tomislav.Datum

[Code] .....

And this is code for filtering by typing into textbox, when type nothing happening

private void textBox3_TextChanged(object sender, EventArgs e) {
DataView DW2 = new DataView(dt);
DW2.RowFilter = string.Format("dogadjaji.dogadjaj LIKE '%{0}%'", textBox3.Text);
dataGridView1.DataSource = DW2;

[Code] .....

And this is by filtering on dataPickers, range of date, and show me what happens on that dates, but show me exception when click button

private void button1_Click(object sender, EventArgs e) {
if(dateTimePicker1.Value>dateTimePicker2.Value) {
MessageBox.Show("Takav opseg nije moguc. Datum Od mora biti veci od datuma Do.", "Opseg datuma", MessageBoxButtons.OK, MessageBoxIcon.Error);

[code].....

View 13 Replies View Related

C :: Implementing Simple Transparent Proxy With Filtering

Feb 9, 2014

My question is mainly about networks. I wan to implement a simple transparent proxy in C, which will filter the browsed sites according to URL blacklist (check before sending the HTTP request) and keywords in content (check the <meta> in the HTML that was responded).

How can I do this? Listen in a local socket (ex. 8080), set the proxy in my browser and according to the requests that the browser sends to me open a socket with the server, forward the browser's request to the server and forward the server's response to the browser? (Of course by applying filters in the stages where needed.

View 7 Replies View Related

C++ :: Accept Integer Array And Its Size As Arguments And Assign Elements Into 2 Dimensional Array

Jan 10, 2015

Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is

1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

View 1 Replies View Related

C# :: Filtering Invalid Byte Sequences For UTF8 Encoding For A Postgre?

Jun 25, 2014

Basically, I am inserting data from an ODBC connection into a PostgreSql database using the COPY query, but the COPY query stops and returns this error...

Quote
ERROR: invalid byte sequence for encoding "UTF8": 0x92
CONTEXT: COPY [TableName], line 1: "189572|1-00-1202|1-|00-|1202||AP||1...
STATEMENT: COPY [TableName] FROM STDIN (DELIMITER '|', NULL '')

View 4 Replies View Related

C :: 2 Dimensional Array Max And Min

Apr 20, 2013

I was able to get the max to work but I cant get the min. it returnning something like -125863456.

Code:
int maxx(int a[][10]);
int minn(int a[][10]);
int main(void){
int array[][10] = { { 2, 7, 6, 8, 4}, {3, 9, 1, 5, 6} };
int max1, min1;

[Code] .....

View 3 Replies View Related

C++ :: 3 Dimensional Array Printing?

Oct 25, 2013

I want to make a program that asks the user for a message and then print out a large graphic of that message. For example, if the user types "he" I want to print out

H..................H EEEEEEEEE
H..................H E
H..................H E
H..................H E
HHHHHHHHHH EEEEEEEEE
H..................H E
H..................H E
H..................H E
H..................H EEEEEEEEE

(treat the periods as spaces. I only put them there because it wouldn't separate the H's correctly.)

I will loop this to continue until the user types quit.

1. How would I set this up to store the user input characters into an array?

2. How would I print out the stored data in the shape of the word?

View 4 Replies View Related

C :: How To Create 8 Dimensional Array

Dec 19, 2014

Is it possible to create an 8 dimensional array in C? If no, then what can I do to improvise or let say bypass the limit?

View 7 Replies View Related

C++ ::  Deleting Two Dimensional Array

Oct 21, 2014

Consider the following code snippet:

GLfloat box[4][4] = {
{ x2, -y2, 0, 0 },
{ x2 + w, -y2, 1, 0 },
{ x2, -y2 - h, 0, 1 },
{ x2 + w, -y2 - h, 1, 1 },
};

Do I need to call a variant of

delete [] box;

Against this float array?

View 1 Replies View Related

C++ :: Two Dimensional Array With Pointer?

Apr 1, 2013

int sum(int (*ar2)[4], int size);

// I dont know what the ar2 is going on

int main(){
int data[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int total = sum(data, 3)
return 0;
}

View 4 Replies View Related

C# :: Sorting 2 Dimensional Array By Value

Jan 9, 2014

Here is what I have, I have a 1D Array being added to a 2D Array and I need to Sort them by value value 3 in the 2D Array, while maintaining a specific amount. Here is what I have so far:

public static void CheckHS(string[] HS) {
try {
GeneralData.HighScores[10, 0] = "11";
GeneralData.HighScores[10, 1] = HS[1];
GeneralData.HighScores[10, 2] = HS[2];
GeneralData.HighScores[10, 3] = HS[3];
//Need Sort Data - Bubble Sort?
}//end Try
catch (Exception ex) { MessageBox.Show(ex.Message); }
}

I am thinking bubble sorting but I remember reading about something faster. Unfortunately I can't find it on the web. The idea is that there will be always 10 Values and 4 Columns on the 2D Array. [The 11th Row being empty at the end of it.

View 14 Replies View Related

C/C++ :: How To Create 4 Dimensional Array

Apr 24, 2013

I want to create 4 dimensional array, in that first three dimenstional are fixed size and the final index will be on 0 to N-numbers.

E.g., double array[500][25][10][<NOT FIXED>].. So I cant create statically, because the index size are more. Also I have tried 4 dimenstional vector, but its giving 2 problem.

(i) I am storing 4th dimenstion size is more than vector[0][0][0].max_size()
(ii) Storing and Retrieving its more time in vector

So, any other solution to store large array which is 3 index is FIXED and final one is not FIXED?

View 16 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved