Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Removing the county boundaries in an image

Subject: Removing the county boundaries in an image

From: Terence Britton

Date: 15 Nov, 2010 12:29:05

Message: 1 of 7

Hi I am trying to take a gradient scale image of the earth (image here: http://photojournal.jpl.nasa.gov/jpegMod/PIA12097_modest.jpg) and remove the black lines that indicate the boundaries of the countries, just leaving me with a smooth gradient of colour contours. I have been looking into some functions within the image processing toolbox but cannot seem to find a function that does the job. I am brand new to matlab, and really need some help.


Thanks

Subject: Removing the county boundaries in an image

From: Sean de

Date: 15 Nov, 2010 15:42:04

Message: 2 of 7

"Terence Britton" <terence.britton@student.manchester.ac.uk> wrote in message <ibr92g$579$1@fred.mathworks.com>...
> Hi I am trying to take a gradient scale image of the earth (image here: http://photojournal.jpl.nasa.gov/jpegMod/PIA12097_modest.jpg) and remove the black lines that indicate the boundaries of the countries, just leaving me with a smooth gradient of colour contours. I have been looking into some functions within the image processing toolbox but cannot seem to find a function that does the job. I am brand new to matlab, and really need some help.
>
>
> Thanks

One way:
Apply a threshold to identify the black lines
nanmap = I(:,:,1)<10; %may need to be higher or lower than 10

convert the whole thing to double
I = double(I);

set the nanmap to nans
I(nanmap) = nan;

and use John D'Errico's inpaint_nans, available here:
http://www.mathworks.com/matlabcentral/fileexchange/4551
to cover them. Then convert back to your class. You'll have to do each channel separately i.e.:
I = image_double_with_nans;
for ii = 1:3
   I(:,:,ii) = inpaint_nans(I(:,:,ii))
end

-Sean

Subject: Removing the county boundaries in an image

From: Terence Britton

Date: 15 Nov, 2010 16:39:04

Message: 3 of 7

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibrkcc$qn$1@fred.mathworks.com>...
> "Terence Britton" <terence.britton@student.manchester.ac.uk> wrote in message <ibr92g$579$1@fred.mathworks.com>...
> > Hi I am trying to take a gradient scale image of the earth (image here: http://photojournal.jpl.nasa.gov/jpegMod/PIA12097_modest.jpg) and remove the black lines that indicate the boundaries of the countries, just leaving me with a smooth gradient of colour contours. I have been looking into some functions within the image processing toolbox but cannot seem to find a function that does the job. I am brand new to matlab, and really need some help.
> >
> >
> > Thanks
>
> One way:
> Apply a threshold to identify the black lines
> nanmap = I(:,:,1)<10; %may need to be higher or lower than 10
>
> convert the whole thing to double
> I = double(I);
>
> set the nanmap to nans
> I(nanmap) = nan;
>
> and use John D'Errico's inpaint_nans, available here:
> http://www.mathworks.com/matlabcentral/fileexchange/4551
> to cover them. Then convert back to your class. You'll have to do each channel separately i.e.:
> I = image_double_with_nans;
> for ii = 1:3
> I(:,:,ii) = inpaint_nans(I(:,:,ii))
> end
>
> -Sean

Right. I'm sorry, I should have said, I have already done some processing on the image and have turned it onto an array of numbers with discrete values for the variable 'precipitable water vapour'. Therefore my array contains only 12 discrete numbers corresponding to 12 different samples of colour taken from the scale at the bottom. I have also cropped the image so I'm only looking at a 400 by 400 array over Africa. All the country lines have been by default turned into zero's in my array. I think this will make the possibility of getting rid of these zeros (I.e the country lines) much simpler.

So just to clear up, a much simplified version of my array would look like..

 5 5 0 5 5 .......
10 10 0 10 10.......
15 15 0 0 15.......
20 20 20 0 20...
. . . 0 .
. . . 0 0
. . . . .

where the numbers can only be one of 12 discrete numbers (in this case i have only shown numbers 5, 10 ,15 and 20) And the zeros represent the lines of the country. I need to get rid of these lines somehow, maybe an interpolation? I tride to write my own where i just swapped any zeros for the number to the right, but obviously when im in the last column there was nothing to the right so it fails.

Again I'm very new to Matlab so please try to be as elementary as possible with your answer.

Thanks

Subject: Removing the county boundaries in an image

From: Sean de

Date: 15 Nov, 2010 16:50:04

Message: 4 of 7

"Terence Britton" <terence.britton@student.manchester.ac.uk> wrote in message <ibrnn8$m2q$1@fred.mathworks.com>...
> "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibrkcc$qn$1@fred.mathworks.com>...
> > "Terence Britton" <terence.britton@student.manchester.ac.uk> wrote in message <ibr92g$579$1@fred.mathworks.com>...
> > > Hi I am trying to take a gradient scale image of the earth (image here: http://photojournal.jpl.nasa.gov/jpegMod/PIA12097_modest.jpg) and remove the black lines that indicate the boundaries of the countries, just leaving me with a smooth gradient of colour contours. I have been looking into some functions within the image processing toolbox but cannot seem to find a function that does the job. I am brand new to matlab, and really need some help.
> > >
> > >
> > > Thanks
> >
> > One way:
> > Apply a threshold to identify the black lines
> > nanmap = I(:,:,1)<10; %may need to be higher or lower than 10
> >
> > convert the whole thing to double
> > I = double(I);
> >
> > set the nanmap to nans
> > I(nanmap) = nan;
> >
> > and use John D'Errico's inpaint_nans, available here:
> > http://www.mathworks.com/matlabcentral/fileexchange/4551
> > to cover them. Then convert back to your class. You'll have to do each channel separately i.e.:
> > I = image_double_with_nans;
> > for ii = 1:3
> > I(:,:,ii) = inpaint_nans(I(:,:,ii))
> > end
> >
> > -Sean
>
> Right. I'm sorry, I should have said, I have already done some processing on the image and have turned it onto an array of numbers with discrete values for the variable 'precipitable water vapour'. Therefore my array contains only 12 discrete numbers corresponding to 12 different samples of colour taken from the scale at the bottom. I have also cropped the image so I'm only looking at a 400 by 400 array over Africa. All the country lines have been by default turned into zero's in my array. I think this will make the possibility of getting rid of these zeros (I.e the country lines) much simpler.
>
> So just to clear up, a much simplified version of my array would look like..
>
> 5 5 0 5 5 .......
> 10 10 0 10 10.......
> 15 15 0 0 15.......
> 20 20 20 0 20...
> . . . 0 .
> . . . 0 0
> . . . . .
>
> where the numbers can only be one of 12 discrete numbers (in this case i have only shown numbers 5, 10 ,15 and 20) And the zeros represent the lines of the country. I need to get rid of these lines somehow, maybe an interpolation? I tride to write my own where i just swapped any zeros for the number to the right, but obviously when im in the last column there was nothing to the right so it fails.
>
> Again I'm very new to Matlab so please try to be as elementary as possible with your answer.
>
> Thanks

Okay, do exactly what I said above, this just makes it easier:
Inans = double(I);
Inans(Inans==0) = nan;
%Apply John's inpaint_nans

Done!

Subject: Removing the county boundaries in an image

From: Terence Britton

Date: 15 Nov, 2010 17:05:06

Message: 5 of 7

Thanks very much for your help and patience with this Sean, I am very appreciative. Just one question. I have never downloaded from the file exchange before, nor have I called another function from my own code. I guess my final question is (and I'm sorry for being a hideous newb) how do i use johns function once I have downloaded it? How do I incorporate it into my program?

Thanks again

Terence

Subject: Removing the county boundaries in an image

From: Sean de

Date: 15 Nov, 2010 17:15:23

Message: 6 of 7

"Terence Britton" <terence.britton@student.manchester.ac.uk> wrote in message <ibrp82$4ck$1@fred.mathworks.com>...
> Thanks very much for your help and patience with this Sean, I am very appreciative. Just one question. I have never downloaded from the file exchange before, nor have I called another function from my own code. I guess my final question is (and I'm sorry for being a hideous newb) how do i use johns function once I have downloaded it? How do I incorporate it into my program?
>
> Thanks again
>
> Terence

Download it, depending on what platform you're on it'll be in a "dowloads" type folder somewhere. Move it to the MATLAB directory in "Documents" or "My Documents". It'll then be on the MATLAB file path and can be called the same way as any stock function.

Subject: Removing the county boundaries in an image

From: Terence Britton

Date: 15 Nov, 2010 19:42:03

Message: 7 of 7

Brilliant, function works perfectly! :) Thanks again for your help

Terence

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us