0
$\begingroup$

I want to extract the oilspill affected areas in SAR images using thresholding, where the affected area appears as darker than surroundings. Here I am attaching the code, where I am able to extract the white portions in the image.

i=imread('oil.jpg');
figure(1);
imshow(i)
title('Orginal image');
% RGB to Gray conversion;
J=rgb2gray(i);
figure(2);
imshow(J)%Grayscale image
x=imresize(J,[256 256]);% converting the imagesize to 256x256
figure(3);
imshow(x)
k=imadjust(x);
imshow(k)
imhist(k)
y=double(k)
[m n]=size(y);
L=double(255);
% Extracting the white portion;
for i=1:m
    for j=1:n
        z(i,j)=0;
        if y(i,j)>=100 && y(i,j)<=255
            z(i,j)=L;
        end
    end
end
figure(4);
imshow(z)

The image I'm working on is:

enter image description here

$\endgroup$

closed as off-topic by penelope, Dilip Sarwate, jonsca, Matt L., Paul R Mar 20 '14 at 15:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – penelope, Dilip Sarwate, jonsca, Matt L., Paul R
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Hey, Wellcome to DSP. We are generally discouraging questions asking abut specific code, so I'm downvoting your question. We are fine with questions asking about possible approaches, so if you explain what you have tried and where the problems were, we'll be glad to help you and I'll be glad to reconsider my vote. In the meantime, take a look at this question about thresholding and this one about segmentation, they might help you with your approach. $\endgroup$ – penelope Jan 21 '14 at 10:51
  • $\begingroup$ Is it really a SAR image? looks a lot like an airplane camera to me. If it is, then it was already processed to be displayed in false colors and the oil / water segmentation part has already been performed. $\endgroup$ – sansuiso Jan 23 '14 at 9:49
2
$\begingroup$

You are almost there, just deal with your image in the HSV space.

i=imread('http://i.stack.imgur.com/tyeUJ.jpg');
figure(1);
imshow(i)
title('Orginal image');
% RGB to Gray conversion;
% J=i(:,:,2);
ii=rgb2hsv(i);
J=ii(:,:,1);
% J=rgb2gray(i);
figure(2);
imshow(J)%Grayscale image
x=imresize(J,[256 256]);% converting the imagesize to 256x256
figure(3);
imshow(x)
k=imadjust(x);
imshow(k)
imhist(k)
y=double(k);
[m n]=size(y);
L=double(255);
% Extracting the white portion;
for i=1:m
    for j=1:n
        z(i,j)=0;
        if y(i,j)<=1 && y(i,j)>=0.6 || y(i,j)<=0.1
            z(i,j)=L;
        end
    end
end
figure(4);
imshow(z)

enter image description here

Note that if you want your boundary much more accurate, thresholding method will always not be the choice.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.