Depicting neighbouring pixel threshold via a ratio between them
2 次查看(过去 30 天)
显示 更早的评论
I have an RGB sentinel 2 image in an numeric array format mxnx3 (1391x2748x3 double)
I have separted the 3 layers R, G and B into separate mxn arrays (1391x2748 double) and have calculated in excel the ratio between three different locations with my sentinel image in relation to their change in the R, G and B. I.e. Red ratio is 4:3:4. I want to tell my pixels when there is a rational change between neighbouring pixels of the magnitude in R, G and B for the original RGB image (which is a mxnx3, where im sure my problem probably lies) to code each a specific colour. This is the code I have so far.
This is for one sites ratio change at R,G and B that I want to highlight a specific colour on the original RGB image.
RGB_image = im2double(imread('Sentinel-2 L2A from 2019-03-15 2.tiff'));
% RGB_image = imread('Sentinel-2 L2A from 2019-03-15 2.tiff');
R= double(RGB_image(:,:,1)); %change to double to avoid clipping
G= double(RGB_image(:,:,2));
B= double(RGB_image(:,:,3));
%for between three locations
% RGB_RedRation= R
% RGB_GreenRation=
% RGB_BlueRation=
RGB_threshold = zeros(size(RGB_image));
%loop over all rows and columns
for ii= 1:size(RGB_image,1)
for jj= 1:size(RGB_image,2)
%get pixel value
pixel = RGB_image(ii,jj);
%check pixel value and assign new value
if pixel(R>0.0105 & R<0.0115)
new_pixel=1;
if pixel(G>0.0230 & G<0.0236)
new_pixel=1;
if pixel(B>0.0240 & B<0.0246)
new_pixel=1;
elseif pixel(RGB_image>0.0246)
new_pixel=0;
else
new_pixel = pixel;
end
RGB_threshold(ii,jj)=new_pixel;
end
end
I hope this makes sense, any help would be great :)
3 个评论
Image Analyst
2019-4-10
What is a "sentinel 2" image?
What does this mean: "Red ratio is 4:3:4"?
And I don't know what "a rational change between neighbouring pixels of the magnitude in R, G and B for the original RGB image" means. What do you mean by rational?
So let's say you have the three color channel images R, G, and B. And you have 2 locations, so 6 RGB values: r1, g1, b1, r2, g2, and b2. Now what?
Youre using a loop over all pixels. Be aware that a pixel has 8 neighbors, not 2.
When you do
pixel = RGB_image(ii,jj);
%check pixel value and assign new value
if pixel(R>0.0105 & R<0.0115)
pixel is then an array rows wide but 3*columns high - I'm sure not what you expect. And R>0.0105 & R<0.0115 is a binary image the same lateral dimensions as your original image, but with no third (color channel) dimension - it's true or false.
Are you trying to do some sort of masking of the entire image? Are you trying to do some kind of a spatial filtering at each pixel location? What's the bigger context for this? What do you REALLY want to do? Don't just tell us you want to make that for loop work, but tell us something like "I'm trying to reduce noise" or "I'm trying to segment out red things in the image" or whatever it is.
I wish I could tell you what to do bit I have no idea what it is you WANT to do.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!