How to make green region red

1 回表示 (過去 30 日間)
Pat
Pat 2012 年 11 月 30 日
In my picture i have green parts,brown region,in that i want to make green regions as red and brown region as yellow and if other regions are there they must be coloured as majenta,plz help
  2 件のコメント
Jan
Jan 2012 年 11 月 30 日
編集済み: Jan 2012 年 11 月 30 日
@Pat: You are not a beginner in this forum. Please follow the standard procedure:
  1. What are the inputs? "my picture" could be a painting, a JPG file or an indexed image loaded into Matlab already with 3 different colors.
  2. What exactly is "green"? Did you specify this already? Note that there are a lot of shadings between green and brown, such that you have to define the method to distinct them.
  3. What did you try so far and which problems occurred? Show your own effort to motivate others to help you. Currently your question is short and does not define the problem exactly. But a meaningful answer must be long, complicated, consider different interpretations of your description of the wanted solution and a lot of code.
This is a public forum and not an English to M-function machine. Therefore it is a good strategy to spend time and energy to formulate questions as clear as possible, to allow for the efficient creation of answers.
Pat
Pat 2012 年 11 月 30 日
編集済み: Image Analyst 2012 年 11 月 30 日
<http://imgur.com/Jga5o> this is my picture, i tried the following code
clc
clear all
close all
I = imread('imagesh1.bmp');
J = im2double(I);
Imga=I;
R = J(:,:,1);
G = J(:,:,2);
B = J(:,:,3);
[len,wid] = size(R);
% Generation of 2-D Log Chromaticity Image.
for i = 1:len
for j = 1:wid
if ((R(i,j)*G(i,j)*B(i,j))~= 0)
c1(i,j) = R(i,j)/((R(i,j)*G(i,j)*B(i,j))^(1/3));
c2(i,j) = G(i,j)/((R(i,j)*G(i,j)*B(i,j))^(1/3));
c3(i,j) = B(i,j)/((R(i,j)*G(i,j)*B(i,j))^(1/3));
else
c1(i,j) = 1;
c2(i,j) = 1;
c3(i,j) = 1;
end
end
end
Img = double(R);
rho1 = mat2gray(log(c1));
rho2 = mat2gray(log(c2));
rho3 = mat2gray(log(c3));
X1 = mat2gray(rho1*1/(sqrt(2)) - rho2*1/(sqrt(2))); %(1/sqrt(2); -1/sqrt(2); 0)
X2 = mat2gray(rho1*1/(sqrt(2)) + rho2*1/(sqrt(2)) - rho3*2/(sqrt(6))); %(1/sqrt(6); 1/sqrt(6); -2/sqrt(6))
theta = 10;
InvariantImage = cos(theta*pi/180)*X1 + sin(theta*pi/180)*X2;
figure,imshow(InvariantImage)
sigma =3;
sigma_phi = 0.5;
K = fspecial('gaussian',2*round(2*sigma)+1,sigma);
K_phi = fspecial('gaussian',5,sigma_phi);
[nrow,ncol] = size(Img);
phi = ones(nrow,ncol);
phi(15:nrow-15,15:ncol-15) = -1;
% figure; imagesc(Img,[0 255]);colormap(gray);hold on;
% contour(phi,[0 0],'b');
% title(iterNum);
timestep = 1;
epsilon = 1.5;
for n = 1:600
[IND,map] = rgb2ind(Imga,5);
[phi,f1,f2,Hphi]= se(Img,phi,timestep,epsilon,K);
phi = conv2(phi,K_phi,'same');
if mod(n,40)==0
pause(0.0001);
hold on;contour(phi,[0 0],'b');
iterNum=[num2str(n), ' iterations'];
hold off;
end
end
imshow(R)
figure,imshow(G)
figure,imshow(B)
figure,imshow(InvariantImage)
figure,imshow(InvariantImage)
colormap(jet)
but not getting as it is

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2012 年 11 月 30 日
Pat, we can't run that. You didn't supply se(). But why not just convert to HSV colorspace, and threshold the image to find the green and brown pixels? Then use those masks as masks to replace the green pixels with red pixels and the brown pixels with yellow pixels. Since this sounds pretty much useless in the real world but sounds extremely like what a class exercise would be I can't do it for you but it's pretty much done in my demo http://www.mathworks.com/matlabcentral/fileexchange/28512-simple-color-detection-by-hue Otherwise all I can say is that your code is wrong somehow but I can't figure it out because we can't run it, but I don't really see any replacement of colors going on.
  3 件のコメント
Image Analyst
Image Analyst 2012 年 11 月 30 日
Yes, like this
imageBlock(:,:,1) = seaColor(1); % Assign the red component.
imageBlock(:,:,2) = seaColor(2); % Assign the green component.
imageBlock(:,:,3) = seaColor(3); % Assign the blue component.
Pat
Pat 2012 年 12 月 6 日
I got the below coding from your demo in one site where the image is divided into blocks..
clc;
close all;
rgbImage = imread('im9.bmp')
rgbImage=imresize(rgbImage,[256 256]);
imshow(rgbImage);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
[rows columns numberOfColorBands] = size(rgbImage)
blockSizeR = 64;
blockSizeC = 64;
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
if numberOfColorBands > 1
ca = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(rgbImage, blockVectorR, blockVectorC);
end
plotIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
subplot(numPlotsR, numPlotsC, plotIndex);
rgbBlock = ca{r,c};
imshow(rgbBlock);
[rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
plotIndex = plotIndex + 1;
end
end
I have 16 blocks as shown in link
http://imgur.com/xmT3Q
now in this some blocks may have same mean value,i have to give same colours for blocks having same mean value,and other colours for other blocks,please help

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by