当前位置:网站首页>MATLAB image interactive operation, the mouse selects an area of the image
MATLAB image interactive operation, the mouse selects an area of the image
2022-07-18 07:54:00 【Xuan yanru Liu】
Sometimes we need to take out part of the image , And it may be different every time , Using code to get some trouble , It is better to draw this area with the mouse , And take it out .
matlab It comes with some functions for interactive image operation , Record it here ;
- getpt
effect : You click a pixel of the image with the mouse , Return the position of this pixel
usage :[x,y] = getpts
Example :
img = imread('lena.jpg');
figure;imshow(img)
[x,y] = getpts; %x Is listed ,y Yes
- getrect
effect : Select a rectangular area
usage :p= getpts;p Four numbers returned , The columns of pixels in the upper left corner are in turn , Row of pixels in the upper left corner , Column length , governor , From these four values, we can determine a rectangular area .
Example :
img = imread('lena.jpg');
imshow(img)
p = getrect; % Return area location information
p = round(p);
I = img(p(2):p(2)+p(4),p(1):p(1)+p(3)); % Index image
- imcrop
effect : Select a rectangular area , Follow getrect almost
usage :I = imcrop(img); Return value I Is the sub image you selected , It's no longer a regional location .
Example :
img = imread('lena.jpg');
% imshow(img)
I = imcrop(img); % Return area location information
The above is the method of taking points and rectangular boxes , The above functions can already meet a large part of the requirements , Sometimes you may need to extract other shapes ,matlab There are many ways to intercept images , I'll sort it out , If you have needs, you can click the link .
| The name of the function | effect |
|---|---|
| drawcircle | Extract a circular area on the image |
| getline,drawline | Extract a straight line |
| drawpolyline | Extract multiple lines ( Such as broken line ) |
| drawrectangle | Extract rectangular area |
| drawellipse | Extract ellipse region |
| drawfreehand | Extract any region |
| drawpolygon | Extract polygon area |
If you use the functions in the table , Pay attention to one problem , We usually extract an image , Not just to draw , Maybe it's more about the value in the sub image , But the functions in the table do not directly take out the value , Here I am inROI Function traverses the original image , Specific examples :
path = 'lena.jpg';
img = double(imread(path));
imshow(img/255)
h = drawpolygon % Extract polygon sub image
data = [];
for i = 1:size(img,1)
for j = 1:size(img,2)
img_tar(i,j) = inROI(h,j,i); %ROI Binary image
if img_tar(i,j)==1
data = [data img(i,j)]; %ROI The data in
end
end
end
figure;imshow(img_tar)
边栏推荐
- Think of multithreading concurrency is guilty? Let's consolidate these basic knowledge of threading first!
- Two way merge sort summary
- 秋招拿了6offer,总结了20多类1100道面试题含答案解析
- How can cloud digital innovation shape the happiness of a city?
- 每日一题·873.最长的斐波那契子序列的长度.记忆化搜索
- Lifecycle:生命周期感知型组件的基础 —— Jetpack 系列(1)
- Firewall ha configuration
- 根据经纬度计算两点之间的距离
- Pytorch中torch.sort()和torch.argsort()函数解析
- Pytorch中[:,None]的用法解析
猜你喜欢

VSCode【因为在此系统上禁止运行脚本】

676. Implement a magic dictionary prefix tree

李沐动手学深度学习V2-目标检测数据集

(零六)Flask有手就行——配置静态文件

競賽·6116·計算布爾二叉樹的值·遞歸

Calculate the distance between two points according to longitude and latitude

蓝领困顿,直播带岗是真伪需求?

缓存穿透、缓存雪崩、缓存击穿?

Pytorch中torch.sort()和torch.argsort()函数解析

JVM tuning command encyclopedia and common command tools and practical steps
随机推荐
Pytorch中torch.argmax()函数解析
LDAP介绍
每日一题·1217.玩筹码·贪心
中金财富证券是正规证券公司吗?开户安全吗
浅析与云基础架构相关的风险 及对应防御措施
会用redis吗?那还不快来了解下redis protocol
Redis+caffeine two-level cache enables smooth access speed
oracle跨网断转发如何解决?
Sorting out knowledge points of binarytree and heap
MySQL 为什么临时表可以重名 ?
leetcode 605. Can place flowers planting problem (simple)
(shangsilicon Valley) JDBC general review
竞赛·6116·计算布尔二叉树的值·递归
C # trick to get all enumeration values of enumeration
驳'一切不谈考核的管理都是扯淡'
Analysis of risks related to cloud infrastructure and corresponding defense measures
LAN attack and network device security configuration
One question per day · 873 The length of the longest Fibonacci subsequence Mnemonic search
今天,深圳华强北又跑出一个芯片IPO
My first anniversary of creation