7 editing title to clarify question

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}][]}]

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]: 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: 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: 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: 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}][]}] 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}][]}]

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]: 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: 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: 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: 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}][]}] 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}][]}]

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]: 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: 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: 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: 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}][]}] 6 fixed code and 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}][]}]

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]: 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: 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: 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: 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}][]}] 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}][]}]

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]: 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: 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: 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: 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}][]}]

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]: 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: 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: 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: 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}][]}] 5 re: Simon Woods

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}][]}]

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]: 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: 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: 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: 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}][]}]

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]: 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: 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: 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}][]}]

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]: 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: 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: 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: 4 re: Szabolcs
3 added 1 characters in body; edited title
2 edited body
1