Threshoding image between certain range [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How to Threshold image between certain range?
i have done this but it doesn't work.
for (int i=0;i<s.size().height;i++)
{
for(int j=0;j<s.size().width;j++)
{
int k=int (s.at<uchar>(j,i));
if (k>6 && k<10)
k=255;
else k=0;
s.at<uchar>(j,i)=k;
}
}

You get an uchar value, and convert it to integer. Try this :
uchar k= s.at<uchar>(j,i);
if (k>6 && k<10) {
k=255;
}else {
k=0;
}
s.at<uchar>(j,i)=k;
I think it may work.

Related

How to dynamically creat variables in a loop(c++) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to create some variables in a loop,e.g.
for(int i = 0; i < _vector.size(); i++) //_vector is a vector struct
{
auto v = _vector.at(i);
auto xi = get_name(v); //how to create x0,x1,x2,x3.....dynamically in this loop
}
anyone knows how to do it like that?
thanks very much!
If you want to reference these variables as x1, x2, etc., it would be better to create a vector to store these.
The code below is written to support integers, however, this can be replaced with another data type.
vector<int> x;
for(int i = 0; i < _vector.size(); i++) //_vector is a vector struct
{
auto v = _vector.at(i);
x.push_back(get_name(v)); //sets the value of x.at(0), x.at(1)...
}

C++ Condition to check for lower number with a treshold [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
There surely has to be a better way to do this in C++ that this ?
if ( width_value < tipWidth )
{
if (tipWidth < threshold)
{
return threshold;
}
return tipWidth;
}
return width_value ;
return std::max(width_value, std::max(tipWidth, threshold))
Or since C++11:
return std::max({width_value, tipWidth, threshold})
That's assuming you #include <algorithm> and the type of width_value, tipWidth, threshold is the same. If not the same, you have to specify it explicitly, e.g. std::max<int>(...)

C++: Algorithm wrong output ( works on java ) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can someone help me with my code ? I'm trying to use different algorithm but it returns way to big numbers, when i use algorithm between /* */ it works perfect, anyone can see whats wrong with my new code ? (same on java works)
int* czynnikiPierwsze(int n)throw (string){
if(n<0){
string wyjatek1="Nie mozna rozlozyc ujemnej liczby";
throw wyjatek1;
}
int b=0;
while(n>2){
n=n/tab[n-2];
b++;
}
dzielniki=new int[b]();
int j=0;
while(n>2){
dzielniki[j]=tab[n-2];
n=n/tab[n-2];
j++;
}
/* int a=n;
int*dzielniki=new int[30]();
for(int j=0;j<n+a;j++){
while(n>2){
dzielniki[j]=tab[n-2];
n=n/tab[n-2];
break;
}
}*/
return dzielniki;
}
There's no chance your second while(n>2) loop runs even once, since the first loop only exited when that same condition was no longer true.

how to create a chain of processes using fork()? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to create 10 processes but not fanned out but rather in a chain. So process 1 is
This is untested:
for( int generation = 0 ; generation < 10 ; ++generation )
{
int pid = fork();
if( pid != 0 )
{
// Do parental things, including wait
break;
}
// Do childish things before forking.
}
Each child knows its own generation.

if statement doesn't work with function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
void skaitoInformacija(){
ifstream duomenys("duom.txt");
int eil_nr;
duomenys >> eil_nr;
string eil[eil_nr];
string nereikalinga_eilute;
getline(duomenys, nereikalinga_eilute);
for(int i=0; i<eil_nr; i++){
getline(duomenys, eil[i]);
if(salinamTarpus(eil[i]) == "good"){ //this if statement doesn't work
}
}
}
void salinamTarpus(string eil) {
...
}
void salinamTarpus(string eil)
your function is not returning anything that you can compare with "good" string
you need to change it to return at least some result if you want to compare it...
string salinamTarpus(string eil) {
if(eil == "okString") // string eil is the right one
{
return "good";
}
return "bad";
}
also if your function salinamTarpus(string eil) returns only 2 values("good","bad") it might be better idea to return boolean,char or so. string is a little bit too much overkill