MATLAB中像素颜色的变化
我将一些像素颜色(首先在矢量MATLAB中像素颜色的变化,matlab,colors,pixel,Matlab,Colors,Pixel,我将一些像素颜色(首先在矢量行中的像素)更改为绿色,但图像会更改此像素值,但所有图像均为红色,我的原始图像img\u裁剪为双rgb 我的代码如下: for j=1:size(img_crop,2)%column img_crop(row_first(1,j),j,1)=0; img_crop(row_first(1,j),j,2)=1; img_crop(row_first(1,j),j,3)=0; end Row_first是一个向量,在第一行中
行中的像素
)更改为绿色,但图像会更改此像素值,但所有图像均为红色,我的原始图像img\u裁剪
为双rgb
我的代码如下:
for j=1:size(img_crop,2)%column
img_crop(row_first(1,j),j,1)=0;
img_crop(row_first(1,j),j,2)=1;
img_crop(row_first(1,j),j,3)=0;
end
Row_first是一个向量,在第一行中有rowsindex,每列为图像_裁剪中的像素,我希望将其更改为绿色
基本上,我想找到第一个最大值(行值最高,然后在此之前找到下一个最小值),然后是对应于我的条件的最小值(不重要),然后绘制第一个最小像素
这是我编写的代码,如下所示
for x = 1:size(img_gauss,2)
% for y=1:size(img_gauss,1)
% Make a row wise intensity distribution graphic for each column starting
%from the first row to the last because findpeaks will assigned the
%indices in that order, and then select the last
%max will correspond to the far adventtitia
%Find the peaks,local maximum for each column and assignment to the
%respective column
[z,local_min] = findpeaks(-img_gauss(1:size(img_gauss,1),x));%local min
% Verify if this local minimum pixels are possible candidates for
% lumen:
for w=1:size(local_min,1)%rows
if (mean_pixel(local_min(w,1),x)<0.0004705 && std_pixel(local_min(w,1),x)<0.0017)
lumen_local(w,x)=local_min(w,1);
else
nao_lumen(w,x)=local_min(w,1);
end
end
% coordinates of the local maximum values
[g,local_max]=findpeaks(img_gauss(1:size(img_gauss,1),x));%local max
local_max(:,x)=local_max(:,1);
% Assignm each maximum and minimum position to the respective column,
%per iteration, and sort both in a descendent way
max_column(1:size(local_max,1),x)=sort(local_max(1:size(local_max,1),x),'descend');
min_column(1:size(lumen_local,1),x)=sort(lumen_local(1:size(lumen_local,1),x),'descend');
% BW = imregionalmin(img_gauss(y,x));
end
% end
for q=1:size(img_gauss,2)
for a=1:size(img_gauss,1)
if mean_pixel(a,q)<0.0004705 && std_pixel(a,q)<0.0017
img_gauss(a,q)=1;%white
else
img_gauss(a,q)=0;%black
end
end
end
figure(9), imshow(img_gauss);
img_close=imclose(img_gauss,ones(20,20));
figure(10),imshow(img_close);
% The first maximum with the highest row number correspond to the
% adventícia,so now the first minimum before correspond to the lumen
for i=1:size(max_column,2)
max_adve(:,i)=max_column(1,i);% [row col] of the the first adventicia pixel
row_first(1,i)= min_column(find(min_column(:,i)<max_adve(:,i),1),i);
end
% Put the lumen pixels at green
for j=1:size(img_crop,2)%column
img_crop(row_first(1,j),j,1)=0;%R
img_crop(row_first(1,j),j,2)=1;%G
img_crop(row_first(1,j),j,3)=0;%B
end
figure(11),imshow(img_crop);
x=1时的:大小(img_gauss,2)
%对于y=1:尺寸(img_高斯,1)
%为每列开始绘制一行强度分布图
%从第一行到最后一行,因为FindPeak将分配
%按该顺序索引,然后选择最后一个
%max将与far Adventatia相对应
%找到每列的峰值、局部最大值并分配给
%各栏
[z,local_min]=findpeaks(-img_gauss(1:size(img_gauss,1),x));%当地民
%验证此局部最小像素是否可能用于
%流明:
对于w=1:大小(本地最小值,1)%行
if(平均像素(局部最小值(w,1),x)您没有告诉我们如何定义img\u-crop
。但是,通过查看您的代码,我猜您是在声明RGB图像,但您只是将第一个通道设置为img\u-gauss
。以这种方式声明img\u-crop
,然后重试您的代码:
img_crop = cat(3,img_gauss,img_gauss,img_gauss);
您只需更改每列中的1
像素,您确定这是您想要的吗?您的目标是什么?并举例说明row\u first
。我不太明白您是如何更改像素的。您使用row\u first
访问第一个维度(行),但第二个维度(列)随着循环索引j
的变化而变化。这就是你想要的吗?还有,img\u crop
是如何声明的?请展示更多设置图像的代码,并引导我们进入for
循环。你为什么不编辑你的帖子,并解释你实际上想如何编辑像素值呢?如果我理解正确,你会吗ean即使在执行上述代码后,您的整个图像仍保持红色?如果是,则图像像素必须更改为绿色,但您可能没有注意到,因为它只有一个像素。我的意思是,这很少见,因为整个图像是绿色的,但您可以仔细检查。