7 editing title to clarify question
source | link

Weird rasterizationresampling when I try to export an Image

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to Szabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

Simon Woods, your comment did the trickThanks to everyone who commented, the following comment from SimonWoods helped me understand. Here's the final (working) code and the resulting (quite beautiful) image. Thanks!

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[(
   img = domquant[#, 256];
   img = ImageResize[img, {8152, 512}, Resampling -> "Nearest"];
   Print[#, " ", img];
   Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".png"]}],
        img, "PNG"]) &, {FileNames["*.jpg", {jpgpath}][[1]]}]

enter image description here

Weird rasterization when I try to export an Image

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to Szabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

Simon Woods, your comment did the trick. Here's the final (working) code and the resulting (quite beautiful) image. Thanks!

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[(
   img = domquant[#, 256];
   img = ImageResize[img, {8152, 512}, Resampling -> "Nearest"];
   Print[#, " ", img];
   Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".png"]}],
        img, "PNG"]) &, {FileNames["*.jpg", {jpgpath}][[1]]}]

enter image description here

Weird resampling when I try to export an Image

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to Szabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

Thanks to everyone who commented, the following comment from SimonWoods helped me understand. Here's the final (working) code and the resulting (quite beautiful) image.

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[(
   img = domquant[#, 256];
   img = ImageResize[img, {8152, 512}, Resampling -> "Nearest"];
   Print[#, " ", img];
   Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".png"]}],
        img, "PNG"]) &, {FileNames["*.jpg", {jpgpath}][[1]]}]

enter image description here

6 fixed code and image
source | link

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to Szabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

Simon Woods, your comment did the trick. Here's the final (working) code and the resulting (quite beautiful) image. Thanks!

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[(
   img = domquant[#, 256];
   img = ImageResize[img, {8152, 512}, Resampling -> "Nearest"];
   Print[#, " ", img];
   Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".png"]}],
        img, "PNG"]) &, {FileNames["*.jpg", {jpgpath}][[1]]}]

enter image description here

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to Szabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to Szabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

Simon Woods, your comment did the trick. Here's the final (working) code and the resulting (quite beautiful) image. Thanks!

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[(
   img = domquant[#, 256];
   img = ImageResize[img, {8152, 512}, Resampling -> "Nearest"];
   Print[#, " ", img];
   Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".png"]}],
        img, "PNG"]) &, {FileNames["*.jpg", {jpgpath}][[1]]}]

enter image description here

5 re: Simon Woods
source | link

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to a commenter's editSzabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to a commenter's edit, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

Mathematica language newbie here. I wrote the following code to quantize an image:

basepath = "~"
SetDirectory[basepath]
jpgpath = FileNameJoin[{basepath, "jpg"}]
pngpath = FileNameJoin[{basepath, "png"}]

domquant[path_, n_] := 
 Image[{List @@@ 
    DominantColors[Image[ColorQuantize[Import[path], n]], n]}]

(*Convert each jpg in path to its 256-color quantized sample*)
Scan[( \
 img = domquant[#, 24];
    Print[#, " ", img];
Export[
    FileNameJoin[{pngpath, StringJoin[FileBaseName[#], ".jpg"]}],
    img,
    "JPEG", ImageResolution -> 300, 
ImageSize -> {8192, 512}]) &, {FileNames[
"*.jpg", {jpgpath}][[1]]}]

If I change the 24 in the domquant call to a higher value I get what looks like a rasterized image (I think). Specifically, a gradient is applied. For example, here's the result of domquant[#, 256]:

wtf

However, if I leave the value as n = 24 or some other smaller number, I get a nice image like this which has discrete boundaries between each value of n, and is actually what I am trying to achieve:

enter image description here

So, why is 24 the magic number beyond which the blur effect takes place? How can I get an image with nice discrete colors using a higher value of n?

In response to Szabolcs, if I remove the ImageResolution and ImageSize options, I get this image:

enter image description here

Not what I'm looking for. I want to create an image like the second one above, where each of 256 colors is represented discretely, and is of arbitrary size.

In response to Simon Woods, if I add Resampling -> "Nearest" to Export, I ge this image with n=256, again blurry:

enter image description here

4 re: Szabolcs
source | link
3 added 1 characters in body; edited title
source | link
2 edited body
source | link
1
source | link