利用matlab提取并分割RGB图像中的某一个已知像素值的图像1

已知一副RGB图像中的的像素值,利用matlab将其分割出来并以二进制图像形式显示:


 
 
  1. %extract.m
  2. clear all;
  3. I=imread( 'new_original.png');
  4. figure,imshow(I),title( 'Original Image');
  5. bw=im2bw(I, 0. 3);
  6. %figure,imshow(bw),title( 'Gray Image');
  7. rgb=[ 252, 2, 4];
  8. img=extract_rgb(I,rgb);
  9. figure,imshow(im2bw(img)),title( 'Segmentation');


 
 
  1. function out_img = extract_rgb(in_img,color_rgb )
  2. %UNTITLED2 Summary of this function goes here
  3. % in_img 输入图像 color_rgb 需要分割的 rgb像素值
  4. % 提取 RGB彩色图像中的某一个颜色到一个二值图像中为黑色
  5. [rol, row,mut]=size(in_img);
  6. out_img=zeros([rol,row]);
  7. for x= 1:(rol -1)
  8. for y= 1:(row -1)
  9. R=in_img(x,y, 1);
  10. G=in_img(x,y, 2);
  11. B=in_img(x,y, 3);
  12. if((R==color_rgb( 1))&(G==color_rgb( 2))&(B==color_rgb( 3)));
  13. in_img(x,y,:)
  14. out_img(x,y)= 255;
  15. end
  16. end
  17. end
  18. return;
  19. end

Original Image:


Segmentation Result:


				<script>
					(function(){
						function setArticleH(btnReadmore,posi){
							var winH = $(window).height();
							var articleBox = $("div.article_content");
							var artH = articleBox.height();
							if(artH > winH*posi){
								articleBox.css({
									'height':winH*posi+'px',
									'overflow':'hidden'
								})
								btnReadmore.click(function(){
									articleBox.removeAttr("style");
									$(this).parent().remove();
								})
							}else{
								btnReadmore.parent().remove();
							}
						}
						var btnReadmore = $("#btn-readmore");
						if(btnReadmore.length>0){
							if(currentUserName){
								setArticleH(btnReadmore,3);
							}else{
								setArticleH(btnReadmore,1.2);
							}
						}
					})()
				</script>
				</article>
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值