下面给出的是初始图像为彩色图像的情况。

%% Example on how to color select pixels in an image.
% Kawahara (2013).% The original COLOR image.
origImg = imread('1.jpg');
oldorigImg = origImg;
% Make sure the values are within 0-255.
origImg = uint8(origImg);% View the original image.
figure; fId = imagesc(origImg); axis image;
title('click and hold mouse to draw on the original image'); % The user draws on the image to select the pixels to highlight.
M = imfreehand();% 0 = background pixels (do not change).
% 1 = foreground pixels (change these colors).
maskImg = M.createMask;% View the black and white mask.
figure; imagesc(maskImg); colormap gray; axis image;% Now let's color the mask green to make it more interesting.
% To do this, we have to make three matrices, one for each color channel.% Increase the color by half the max value so we can see some transparancy
% in the original image.
amountIncrease = 255/2;alphaImg(:,:,1) = zeros(size(maskImg)); % All zeros.
alphaImg(:,:,2) = round(maskImg*(amountIncrease)); % Round since we're dealing with integers.
alphaImg(:,:,3) = zeros(size(maskImg)); % All zeros. % Convert alphaImg to have the same range of values (0-255) as the origImg.
alphaImg = uint8(alphaImg);% View alphaImg.
figure; imagesc(alphaImg); axis image;% Combine the original images and the alpha values to highlight the select
% pixels.
blendImg = origImg + alphaImg;% Show the blended images.
figure; imagesc(blendImg); axis image;

效果图

若初始图像为灰度图像时,可用如下代码替换

blendImg = repmat(origImg, [1,1,3]) + alphaImg;

本文转自:
http://kawahara.ca/matlab-how-to-highlight-select-pixels-in-an-image/

matlab如何把选中区域标亮相关推荐

  1. Matlab——离散点的随机区域分配

    Matlab--离散点的随机区域分配 假设待定区域现在有200个离散点,我们随机挑选出10个离散点,并以这10个点为中心画半径为R(任意取)的圆.我们知道这10个圆在没有任何交集的情况下,共有10个区 ...

  2. matlab函数_连通区域 bwareaopen bwarea

    matlab函数_连通区域 1. matlab函数bwareaopen──删除小面积对象 格式:BW2 = bwareaopen(BW,P,conn) 作用:删除二值图像BW中面积小于P的对象,默认情 ...

  3. matlab函数_连通区域regionprops的相关解释

    声明:内容来源:https://www.cnblogs.com/einyboy/archive/2012/08/03/2621820.html 最近在学习对于图像的连通域的求取方法,尤其对于多连通域的 ...

  4. 选定区域着色html,PS怎么填充颜色到选中区域?PS填充颜色到选中区域的方法

    PS是一款非常好用的图片编辑软甲,在平时的工作中经常用到,你知道PS怎么填充颜色到选中区域的吗?接下来我们一起往下看看PS填充颜色到选中区域的方法吧. 方法步骤 1.首先你要确认选择你要填充的区域,然 ...

  5. WebView实现改变选中区域颜色以及添加下划线

    一.Web端实现 最近遇到了一个问题,老大要求实现对WebView加载的html页面实现选中修改背景色以及添加下划线并可以删除,最后可以保存这些修改,下次进入该html界面时仍然能够显示之前添加的背景 ...

  6. Matlab绘制带有填充区域的曲线

    Matlab绘制带有填充区域的曲线 https://zhuanlan.zhihu.com/p/435763835 效果如图所示: clear;clc; syms t n = 50; x = linsp ...

  7. 16.Excel vba开发-计算所选中区域之和

    1.需求:计算所选中区域之和 2.代码 Sub 计算所选中区域之和()Dim r Dim t As Double For Each r In SelectionIf IsNumeric(r.Value ...

  8. Excel·VBA选中区域保存为txt文本

    vba代码有3种写法,都可实现,适用单/多列选中.单/多列部分选中,选中区域内容保存为一个txt文件 Private Function RE_STR(source_str As String, pat ...

  9. html文字滑动时改变颜色,css实现滚动时选中区域字体颜色加深的示例代码

    在封装日期选择器时,需要选中时字体颜色加深,先看一下实现后的效果 可以看到加深的不是整个文字,而是中间那片区域今天聊的重点不在选择器的封装,主要看这个样式效果,想了解此组件的实现思路可以看之前的文章日 ...

最新文章

  1. redis缓存穿透,缓存击穿,缓存雪崩
  2. 「caffe速成」caffe图像分类从模型自定义到测试
  3. wechaty QR code not recognizable..
  4. PHP中如何给日期加上一个月 加一周 加一天
  5. android 百度地图 在线建议查询,百度地图SDK-----百度地图在线建议查询,结合AutoCompleteTextView实现搜索下拉列表。...
  6. jsp中设置自动换行_办公技巧—Word中如何设置自动生成序号
  7. mysql 扩展存储过程_MySQL4:存储过程和函数
  8. PAT乙级(1009 说反话)
  9. springboot访问路径添加项目名称、tomcat端口号
  10. 功夫小子实践开发-基本工具类的分析和实现
  11. 掌握Thinkphp3.2.0----标签库
  12. 十大最热门人工智能技术
  13. Python计算流体动力学(CFD)模拟人体呼吸系统
  14. 甲骨文裁员900多人,赔偿N+6,有人获赔100万,被裁也能致富?
  15. 并查集算法 | Union-Find Algorithm
  16. 通俗说说DSP、SSP、RTB、DMP是什么
  17. 半导体巨头如何拼了老命为摩尔定律延寿
  18. 网易向员工致歉|网易暴力裁员事件:希望网易不要挣了钱,凉了人
  19. PSD-BPA光伏仿真求助
  20. 【JS中scrollHeight/Width详解(不加定位的情况下)】

热门文章

  1. 字典树实现_学习NLP的第3天——字典树
  2. 电脑无法检查计算机更新,赶紧检测下!新买的电脑不能升级Win 11?问题终于找到了...
  3. android studio crashlytics,完美解决Android Studio集成crashlytics后无法编译的问题
  4. 方根法公式_仓储管理笔记之库存分析法:ABC分析法、区域合并法......
  5. git 检查更新文件_Git通过差异比对快速打包待更新文件(SQL)
  6. CST 使用注意事项【持续更新】
  7. PAT_B_1029_Java(20分)
  8. 网络流--最大流--POJ 1273 Drainage Ditches
  9. 【转载】用廉价的315M遥控模块实现数据传输
  10. CSDN移动博文集锦之Android核心分析 (Z)