Skip to main content
Commonmark migration
Source Link

#Matlab, 255 245 231 bytes

Matlab, 255 245 231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = farther away.

enter image description here

#Matlab, 255 245 231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = farther away.

enter image description here

Matlab, 255 245 231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = farther away.

enter image description here

edited body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253

#Matlab, 255 245 231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = furtherfarther away.

enter image description here

#Matlab, 255 245 231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = further away.

enter image description here

#Matlab, 255 245 231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = farther away.

enter image description here

deleted 6 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253

#Matlab, 255 245 245231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros([rr,c]c); m;m(I(''),I(''))=1;M=m;d=m;for=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,[0,1,0;1,1,1;0,1,0]K'*K>1,'same''s')+0;m;m(~i)=0;endz=max=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = further away.

enter image description here

#Matlab, 255 245 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros([r,c]); m(I(''),I(''))=1;M=m;d=m;for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,[0,1,0;1,1,1;0,1,0],'same')+0;m(~i)=0;endz=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = further away.

enter image description here

#Matlab, 255 245 231 bytes

This expects the image name first, then y and then x.

I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[])

I implemented the flood filling (or 'dijkstra for 4-neighbourhoods' if you want) roughly by first creating a mask where the seed pixel is set to 1 and with a distance accumulator (both of the size of the image) and then repeating following steps:

  • convolute the mask with a 4 neighbourhood kernel (this is the very inefficient part)
  • set all nonzero pixels of the mask to 1
  • set all the black pixels of the image to zero
  • set all values in the accumulator where the mask has changed in this step to k
  • increase k
  • repeat until there are no more changes in the mask (I actually do not check this condition, but just use the number of pixels in the image as an upper bound, which is usually a very bad upper bound, but this is codegolf=)

This leaves us with the manhattan distances of every pixel to the seed pixel in the distance accumulator. Then we create a new image by going throu the given range of colours and map the "first" hue to the value zero and the "last" hue to the maximal distance.

#Examples

enter image description here

enter image description here

enter image description here

enter image description here

As a bonus, here a pretty picture of how the distance gets calculated. brighter = further away.

enter image description here

added 1 character in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
added 36 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
added 185 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
added 49 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
added 86 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
added 99 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
added 255 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
added 327 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253
Loading