matlab如何删除像素,如何在Matlab中标记像素?(How to Mark Pixels in Matlab?)

I'm not sure of exactly what you are after with your question, but the code below may help you in achieving the result. If you leave a comment, I can perhaps improve the answer.

0) Read in an image in RGB format.

First option: Separate out green and other components (each plotted separately), and make a final plot of all non-green components set to 1. Note: this results in a fully black image as all components have some amount of green.

Second option: Separate the image into either Red, Green or Blue based on the maximum contribution. The last plot shows the conversion to black and white. Note: The algorithm is not vectorized so this would be slow if processing large/many images.

I = imread('autumn.tif');

IG = I; IG(:,:,[1 3]) = 0; % Green only

INoG = I-IG;

INoG1 = INoG; INoG1(abs(INoG1) > 0) = 1;

% Possibly what you want?

% Display resulting images

subplot(4,2,1)

imshow(I)

title('Original');

subplot(4,2,2)

imshow(INoG)

title('No Green');

subplot(4,2,3)

imshow(IG)

title('Only Green');

subplot(4,2,4)

imshow(INoG1)

title('No Green (all 1?)');

% Note: There is a bit of each color in every pixel...

% => Potential solution: Use major contributor

% Not vectorized => Slow for large images

IRGB = I*0;

for i = 1:size(I,1)

for j = 1:size(I,2)

[~,k] = max(I(i,j,:));

if (size(k) > 1)

k = k(1);

end

IRGB(i,j,k) = 255;

end

end

IRGBG = IRGB; IRGBG(:,:,[1 3]) = 0; % Green only

IRGBNoG = IRGB-IRGBG;

BandWNoG = IRGBG(:,:,2); % Possibly what you want?

% Display resulting images

subplot(4,2,5)

imshow(IRGB);

title('RGB - Original');

subplot(4,2,6)

imshow(IRGBNoG);

title('RGB - No Green');

subplot(4,2,7)

imshow(IRGBG);

title('RGB - Only Green');

subplot(4,2,8)

imshow(BandWNoG)

title('Black and White - No Green');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值