Message Boards Message Boards

0
|
6608 Views
|
9 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Convert a batch of RGB images to Grayscale?

Posted 6 years ago

I have a few RGB images in a folder which i would like to convert to grayscale. I have been able to convert them individually but i am unable to convert all the images in the folder at one go. I have tried to implement ColorConvert and ColorSpace but was unable to convert the complete set of images in one go. I need to convert approximately 2000 images so it is not possible to convert them individually. I request some help to achieve this task.

Thanks

POSTED BY: Pushkar D
9 Replies
POSTED BY: Mikayel Egibyan
Posted 6 years ago

I have tried the updated code and have done the exact same thing which you posted but i am still getting an empty folder without anything in it and the kernel is quitting within seconds of evaluating the notebook.

POSTED BY: Pushkar D

I have updated the reply not to include the original image.

Are you sure you are trying exactly what I posted?

POSTED BY: Mikayel Egibyan
Posted 6 years ago

I have tried what you suggested but the code is just creating an empty folder and is exiting the kernel.

I forgot to mention to you that i do not want the image in the background, i just want the descriptors as jpg without the actual image in the background.

POSTED BY: Pushkar D

You can make a function and use it:

pathToFiles = "/yourPath/..";
SetDirectory[pathToFiles];
newPath = FileNameJoin[{pathToFiles, "newPath"}];
If[!DirectoryQ[newPath],
    CreateDirectory[newPath];
];
files = FileNames["*.jpg", pathToFiles];
Export[FileNameJoin[{newPath, FileNameTake[#, -1]}], customFunc@Import[#]] & /@ files

Now, your customFunc

customFunc[img_Image] :=
    Block[{dims, dirs, magnitudes, orientations},
       dims = ImageDimensions[img];
       dirs = ImageData[GradientOrientationFilter[img, 5]];
       magnitudes = ImageData[GradientFilter[img, 5]];
       orientations = MapThread[#1 {-Sin[#2], Cos[#2]} &, {magnitudes, dirs}, 2];

        ListVectorPlot[
           MapIndexed[{{#2[[2]], dims[[2]] - #2[[1]]}, #1} &, orientations, {2}], 
           VectorColorFunction -> (Yellow &)
        ]
    ]
POSTED BY: Mikayel Egibyan
Posted 6 years ago
POSTED BY: Pushkar D

Please retry.

POSTED BY: Mikayel Egibyan
Posted 6 years ago
POSTED BY: Pushkar D
POSTED BY: Mikayel Egibyan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract