查看: 262|回复: 4|关注: 0

[已答复] 图像背景的去除

[复制链接]

新手

5 麦片

财富积分


050


1

主题

4

帖子

0

最佳答案
发表于 2020-9-19 21:34:05 | 显示全部楼层 |阅读模式
各位大佬,你们好。如何去除P2图像中P1的那一部分?刚接触MATLAB,请多多指教,谢谢!
p2.png
p1.png
回复主题 已获打赏: 0 积分

举报

新手

5 麦片

财富积分


050


1

主题

4

帖子

0

最佳答案
 楼主| 发表于 2020-9-19 21:57:56 | 显示全部楼层
希望能有代码,谢谢各位大神!
回复此楼 已获打赏: 0 积分

举报

新手

5 麦片

财富积分


050


1

主题

4

帖子

0

最佳答案
 楼主| 发表于 2020-9-20 11:38:42 | 显示全部楼层
顶一下。

新手

5 麦片

财富积分


050


1

主题

4

帖子

0

最佳答案
 楼主| 发表于 2020-9-20 21:35:19 | 显示全部楼层
帮帮忙呀,有思路也行:'(
回复此楼 已获打赏: 0 积分

举报

MATLAB 图像处理与计算机视觉
版块优秀回答者

中级

529 麦片

财富积分


5001500


71

主题

1667

帖子

114

最佳答案
  • 关注者: 36
发表于 2020-10-12 09:30:16 | 显示全部楼层
  1. p = rgb2gray(imread('https://www.ilovematlab.cn/data/attachment/forum/202009/19/213151p2fd8ldut14d1g1f.png'));
  2. im0 = rgb2gray(imread('https://www.ilovematlab.cn/data/attachment/forum/202009/19/213151m8g5bpl5zxbx55d5.png'));

  3. pat = im2double(~p);
  4. im = im2double(~im0);
  5. reg = registerImages(pat,im);
  6. im_reg = reg.RegisteredImage;
  7. imshow(im_reg)

  8. pad_flag = imdilate(im_reg,strel('disk',3));
  9. im0(pad_flag==1) = 255;
  10. imshow(im0)
复制代码
  1. function [MOVINGREG] = registerImages(MOVING,FIXED)
  2. %registerImages  Register grayscale images using auto-generated code from Registration Estimator app.
  3. %  [MOVINGREG] = registerImages(MOVING,FIXED) Register grayscale images
  4. %  MOVING and FIXED using auto-generated code from the Registration
  5. %  Estimator app. The values for all registration parameters were set
  6. %  interactively in the app and result in the registered image stored in the
  7. %  structure array MOVINGREG.

  8. % Auto-generated by registrationEstimator app on 12-Oct-2020
  9. %-----------------------------------------------------------


  10. % Feature-based techniques require license to Computer Vision System Toolbox
  11. checkLicense()

  12. % Default spatial referencing objects
  13. fixedRefObj = imref2d(size(FIXED));
  14. movingRefObj = imref2d(size(MOVING));

  15. % Detect SURF features
  16. fixedPoints = detectSURFFeatures(FIXED,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5);
  17. movingPoints = detectSURFFeatures(MOVING,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5);

  18. % Extract features
  19. [fixedFeatures,fixedValidPoints] = extractFeatures(FIXED,fixedPoints,'Upright',false);
  20. [movingFeatures,movingValidPoints] = extractFeatures(MOVING,movingPoints,'Upright',false);

  21. % Match features
  22. indexPairs = matchFeatures(fixedFeatures,movingFeatures,'MatchThreshold',50.000000,'MaxRatio',0.500000);
  23. fixedMatchedPoints = fixedValidPoints(indexPairs(:,1));
  24. movingMatchedPoints = movingValidPoints(indexPairs(:,2));
  25. MOVINGREG.FixedMatchedFeatures = fixedMatchedPoints;
  26. MOVINGREG.MovingMatchedFeatures = movingMatchedPoints;

  27. % Apply transformation - Results may not be identical between runs because of the randomized nature of the algorithm
  28. tform = estimateGeometricTransform(movingMatchedPoints,fixedMatchedPoints,'affine');
  29. MOVINGREG.Transformation = tform;
  30. MOVINGREG.RegisteredImage = imwarp(MOVING, movingRefObj, tform, 'OutputView', fixedRefObj, 'SmoothEdges', true);

  31. % Store spatial referencing object
  32. MOVINGREG.SpatialRefObj = fixedRefObj;

  33. end

  34. function checkLicense()

  35. % Check for license to Computer Vision System Toolbox
  36. CVSTStatus = license('test','video_and_image_blockset');
  37. if ~CVSTStatus
  38.     error(message('images:imageRegistration:CVSTRequired'));
  39. end

  40. end
复制代码

回复此楼 已获打赏: 0 积分

举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

快速回复 返回顶部 返回列表