Subimage Recognition

An image A is said to be a subimage of another image B if it is possible to remove some rows and/or columns of pixels from B so that the resulting image is identical to A. Figure 6 illustrates an example. Image A, shown in Figure 6(a), is a subimage of image B, shown in Figure 6(b), because the image resulting from the removal of the middle row and column of pixels from B is identical to A.

The input contains a single test case. The first line contains two integers r and c (1 ≤ rc ≤ 20), the dimensions of A. The following r lines, each containing a string of length c, give an r × c 0-1 matrix representing the pixels of A. The next line contains two integers R and C (r ≤ R ≤ 20; c ≤ C ≤ 20), the dimensions of B. The following R lines, each containing a string of length C, give an R × C 0-1 matrix representing the pixels of B. A 0 indicates a white pixel; a 1 indicates a black pixel.

If A is a subimage of B, print “Yes”; otherwise, print “No”.


由于r c都是不大于20的,所以我们暴力乱搞一通就好了O(∩_∩)O~~


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[22][22];
char b[22][22];
int r1,c1,r2,c2;
int id[22];
int main(){
    scanf("%d%d",&r1,&c1);
    for(int i=0;i<r1;i++)
        scanf(" %s",a[i]);
    scanf("%d%d",&r2,&c2);
    for(int i=0;i<r2;i++)
        scanf(" %s",b[i]);
    int ans=0;
    for(int i=0;i<(1<<r2);i++){
        int cnt=0;
        for(int k=0;k<r2;k++)
            if((1<<k)&i)
                id[cnt++]=k;
        if(cnt!=r1) continue;
        int st=0;
        int col;
        for(col=0;col<c1;col++){
            int flag=0;
            for(int pc=st;pc<c2;pc++){
                for(int row=0;row<r1;row++){
                    if(a[row][col]!=b[id[row]][pc])
                        break;
                    if(row==r1-1) flag=1;
                }
                if(flag) {st++;break;}
            }
            if(flag==0) {break;}
        }
        if(col==c1){ans=1;break;}
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


在OpenCV中对`subImage`进行操作,通常涉及到图像的预处理、特征提取、变换或简单的图像处理。下面列举一些常见的操作示例: 1. **转换颜色空间**:如果需要将RGB转为灰度或者HSV,可以使用`cvtColor()`函数: ```cpp cv::Mat graySubImage; cv::cvtColor(subImage, graySubImage, cv::COLOR_BGR2GRAY); ``` 2. **滤波**:应用各种滤波器,如高斯滤波、边缘检测等: ```cpp cv::Mat blurredSubImage; cv::GaussianBlur(subImage, blurredSubImage, cv::Size(5, 5), 0); ``` 3. **特征提取**:如果想要识别特定的物体或特征点,可以使用SIFT、SURF或ORB等特征检测器: ```cpp std::vector<cv::KeyPoint> keypoints; cv::GoodFeaturesToTrackDetector detector; detector.detect(subImage, keypoints); ``` 4. **图像增强**:调整亮度、对比度、饱和度等: ```cpp cv::Mat enhancedSubImage; double alpha = 1.5; // 对比度增强系数 cv::equalizeHist(subImage, enhancedSubImage); enhancedSubImage *= alpha; ``` 5. **裁剪或缩放**:如果需要进一步处理某一区域或改变尺寸,可以使用`copyTo()`或resize()函数: ```cpp cv::Mat croppedSubImage; subImageROI(subImage, croppedSubImage, cv::Rect(100, 100, 200, 200)); // 裁剪 cv::resize(croppedSubImage, resizedSubImage, cv::Size(500, 500)); // 缩放 ``` 6. **保存或显示**:处理完后,可以将结果保存到文件或直接显示出来: ```cpp imwrite("output.jpg", enhancedSubImage); imshow("Enhanced Image", enhancedSubImage); waitKey(); ``` 记得在每次操作后检查是否需要释放资源,特别是当处理完一个`Mat`实例后,应该使用`~Mat()`将其析构并自动释放内存。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值