1
$\begingroup$

I have 150 images that I want to import into the Mathematica, and process. I use this code but I get errors. I ran the example for three images.

imgdir = FileNameJoin[{NotebookDirectory[], "Flow pic"}];

{IR, R, G} = 
  Import[FileNameJoin[{imgdir, "le-" <> ToString[#] <> ".jpg"}], 
     "Data"] & /@ {3, 2, 1};

image = Map[ImageTake[#, {50, 630}, {499, 600}] &, 
  Map[ImageResize[#, {900, 650}] &, {IR, R, G}]]

enter image description here

$\endgroup$

2 Answers 2

5
$\begingroup$

Either removing the "Data" format argument or using "JPEG" instead should do it.

Here is a short example based on the original code.

imgdir = FileNameJoin[{NotebookDirectory[], "Flow pic"}];
(*Export three images for testing purpose*)
SeedRandom[42];
images = ExampleData /@ RandomChoice[ExampleData["TestImage"], 3]
Export[FileNameJoin[{imgdir, "le-" <> ToString[#] <> ".jpg"}], 
   images[[#]], "JPEG"] & /@ Range[3];
FileSystemMap[FileSize, imgdir]
(*Output*)

Test images

(*Using Import function with "JPEG" fmt argument*)
imagesA = Import[FileNameJoin[{imgdir, "le-" <> ToString[#] <> ".jpg"}], "JPEG"] & /@ {3, 2, 1};
Map[ImageTake[#, {50, 630}, {499, 600}] &, Map[ImageResize[#, {900, 650}] &, imagesA]]

(*Using Import function w/o fmt argument*)
imagesB = Import[FileNameJoin[{imgdir, "le-" <> ToString[#] <> ".jpg"}]] & /@ {3, 2, 1};
Map[ImageTake[#, {50, 630}, {499, 600}] &, Map[ImageResize[#, {900, 650}] &, imagesB]]
(*Output*)

enter image description here

$\endgroup$
1
  • $\begingroup$ However correct it is, this reads like a comment, and not as an answer worth accepting. Probably you could flesh it out more. $\endgroup$
    – rhermans
    Sep 8, 2023 at 12:07
0
$\begingroup$

Try this....

Test images enter image description here

imgdir = FileNameJoin[{NotebookDirectory[], "Flow pic"}]
imgdata = Import[FileNameJoin[{imgdir,"le-" <> ToString[#] <> ".jpg"}]] & /@ {3, 2, 1};

image = ImageTake[#, {50, 630}, {499, 600}] & /@ ImageResize[#, {900, 650}] & /@ imgdata

enter image description here

$\endgroup$
1
  • $\begingroup$ Tank you, But the last line related to image processing does not work properly $\endgroup$
    – Erfan
    Sep 8, 2023 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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