Clear Filters
Clear Filters

Depicting neighbouring pixel threshold via a ratio between them

1 view (last 30 days)
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 Comments
Image Analyst
Image Analyst on 10 Apr 2019
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.
Erin Browne
Erin Browne on 16 Apr 2019
I have a sentinel 2 image which is a satellite (very commonly known within remote sensing).
It provides me with an RGB image as in a layer of Red, green and blue i whic pixel one [1, 1, 1] between three add up to a ratio of 1 yes?
There is three different locations within this image I want to signifiy using three colours (e.g. a mangrove, water beside the mangrove and coral that is exposed during low tide - all adjacent to each other i.e. kind of the change in RGB ratio along a transect starting from the water over the corals into the mangrove). I have calulated the ratio of the RGB layers in which when the pixel has a specific ratio over these three bands it highlights the area with the mangrove but i know what 1) Colour these areas of differing RGB ratios with a solid colour for each site 2) I know the distance in meters between them so if each pixel is 10m resolution how could I ask for a ratio change in pixel direction over say 7 pixel (=70m) change colour?
This is pretty complex to explain. If you don't understand/I'm not clear let me know.
Thanks

Sign in to comment.

Answers (0)

Categories

Find more on Agriculture in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!