Image filter 1066 (15 minutes)
The image is the filtered image pixels are unimportant dyed background color, so that the important part is highlighted. Now given a monochrome image, the gray value is located in claim you all pixels within a designated color range are replaced with one specified color.
Input format:
input a given resolution image in the first row, i.e., two positive integers M and N (0 <M, N≤500) , the other is to be filtered gray value interval endpoints A and B (0 ≤A <B≤255), and replacing the tone value specified. Subsequently M rows, each row of the N gradation values given pixel, separated by a space therebetween. All the gradation values are within [0, 255] interval.
Output format:
image output filtering required. I.e. M output lines, each of the N pixel grayscale values, each representing three gradation values (e.g. 000 to be displayed in black), separated by a space therebetween. Line from beginning to end may not have the extra space.
Sample input:
. 3. 5 0 100 150
. 3 189 254 119 101
150 151 99 233 100
88 123 149 0 255
Output Sample:
003.189254 trillion
000 233 151 099 000
088 000 000 000 255
#include <iostream>
using namespace std;
int main()
{
int M,N,A,B,gray;
cin>>M>>N>>A>>B>>gray;
int i,j,point[M][N];
for(i=0;i<M;i++){
for(j=0;j<N;j++){
cin>>point[i][j];
if(point[i][j]>=A&&point[i][j]<=B){
point[i][j]=gray;
}
}
}
for(i=0;i<M;i++){
for(j=0;j<N;j++){
printf("%03d",point[i][j]);
if(j<N-1){
printf(" ");
}
}
printf("\n");
}
}