citra=imread('ISIC_0024336.jpg');
figure, fig1=imshow(citra);
load mri
V = squeeze(citra);
citra3=montage(reshape(V,size(citra)),map,'Indices',3);
saveas(citra3,'ISIC_0024336coba.jpg');
Would you help me please, How to save the output image in Matlab automatically?

2 comentarios

citra3=montage(reshape(V,size(citra)),map,'Indices',3);
since V is squeezed citra, reshape of it back to size of citra would just give you back citra... so why bother with the shape change and why not just pass citra into montage?
Frisda Sianipar
Frisda Sianipar el 23 de Feb. de 2021
actually I use this code to remove the background from the image only. And after that I want to save the output automatically, but I don't know what to use.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Feb. de 2021

0 votos

infile = 'ISIC_0024336.jpg';
citra=imread(infile);
figure, fig1=imshow(citra);
load mri
V = squeeze(citra);
citra3=montage(reshape(V,size(citra)),map,'Indices',3);
[folder, basename, ext] = fileparts(infile);
outfile = fullfile(folder, [basename 'coba' ext]);
saveas(citra3, outfile);

13 comentarios

Frisda Sianipar
Frisda Sianipar el 24 de Feb. de 2021
Thankyou for the answer. But i confuse of basename and ext, could you explain it?
And folder , can i make like this ''F:\kuliah\semester6\TA2\Implemen'?
Thankyou
infile = 'ISIC_0024336.jpg';
[folder, basename, ext] = fileparts(infile)
folder = 0×0 empty char array
basename = 'ISIC_0024336'
ext = '.jpg'
That is, folder, basename, and ext are output of analyzing the filename. folder will store the folder info extracted from the filename. basename will store the filename without the last extension. ext will store the '.' and content of the extension.
Then once those are known, I put them back together again with 'coba' just before the extension, reflecting that your saveas(citra3,'ISIC_0024336coba.jpg'); has the same name as the file you read from except with 'coba' added.
If you want to write your output to a different folder, then that is no problem:
outfolder = 'F:\kuliah\semester6\TA2\Implemen';
if ~isdir(outfolder); mkdir(outfolder); end
load mri %I presume it has the variable map in it
infile = 'ISIC_0024336.jpg';
citra=imread(infile);
imshow(citra);
V = squeeze(citra);
citra3=montage(reshape(V,size(citra)),map,'Indices',3);
[~, basename, ext] = fileparts(infile);
outfile = fullfile(outfolder, [basename 'coba' ext]);
saveas(citra3, outfile);
Frisda Sianipar
Frisda Sianipar el 24 de Feb. de 2021
Thankyou, but after I tried the image was not saved in the specified folder. Could you help me again?
Walter Roberson
Walter Roberson el 24 de Feb. de 2021
Not sure why you say it was not saved in the specified folder? That folder is the same as your current folder according to the address bar at the top of the folder browser, and we can see from the left that the folder has ISIC_0024336coba.jpg . So as far as I can see, it did write the file into the given folder.
Frisda Sianipar
Frisda Sianipar el 24 de Feb. de 2021
Thankyou somuch, the image has been save.
Frisda Sianipar
Frisda Sianipar el 24 de Feb. de 2021
Editada: Walter Roberson el 24 de Feb. de 2021
can you help me again? I want to process multiple images and save them right away. I have got the code to read multiple images in one folder. But i don't understand to mix them. This is the code:
clc;
clear all;
image_folder = 'F:\kuliah\semester5\TA\Implementasi';
filenames = dir (fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
for n = 1:total_images
f = fullfile(image_folder, filenames(n) .name);
our_images = imread(f)
figure (n)
imshow(our_images)
end
image_folder = 'F:\kuliah\semester5\TA\Implementasi';
outfolder = 'F:\kuliah\semester6\TA2\Implemen';
if ~isdir(outfolder); mkdir(outfolder); end
load mri %I presume it has the variable map in it
fileinfo = dir(fullfile(image_folder, '*.jpg'));
filenames = fullfile({fileinfo.folder}, {fileinfo.name});
total_images = numel(filenames);
for n = 1 : total_images
thisfile = filenames{n};
[~, basename, ext] = fileparts(infile);
citra = imread(thisfile);
V = squeeze(citra);
fprintf('processing %s\n', basename);
citra3 = montage(reshape(V,size(citra)), map, 'Indices', 3);
outfile = fullfile(outfolder, [basename 'coba' ext]);
saveas(citra3, outfile);
end
With a reminder that if you are not doing any processing on V, then you could make this shorter as
image_folder = 'F:\kuliah\semester5\TA\Implementasi';
outfolder = 'F:\kuliah\semester6\TA2\Implemen';
if ~isdir(outfolder); mkdir(outfolder); end
load mri %I presume it has the variable map in it
fileinfo = dir(fullfile(image_folder, '*.jpg'));
filenames = fullfile({fileinfo.folder}, {fileinfo.name});
total_images = numel(filenames);
for n = 1 : total_images
thisfile = filenames{n};
[~, basename, ext] = fileparts(infile);
citra = imread(thisfile);
fprintf('processing %s\n', basename);
citra3 = montage(citra, map, 'Indices', 3);
outfile = fullfile(outfolder, [basename 'coba' ext]);
saveas(citra3, outfile);
end
Frisda Sianipar
Frisda Sianipar el 24 de Feb. de 2021
thankyou, I have tried the code you provide. A folder containing many images has been read, but only one output is stored.
Frisda Sianipar
Frisda Sianipar el 24 de Feb. de 2021
could you give the solution please?
Walter Roberson
Walter Roberson el 24 de Feb. de 2021
you asked for the images to be stored in the Implemen subdirectory of the place you are looking.
Frisda Sianipar
Frisda Sianipar el 24 de Feb. de 2021
yes, I want to save the results in a new folder. But there are 3 images that I processed, but only 1 stored
implemencoba.fig is not one of the output files. You need to look inside the Implemen directory of where you are now.
dir('F:\kuliah\semester6\TA2\Implemen')
Frisda Sianipar
Frisda Sianipar el 25 de Feb. de 2021
yes, it same. nothing is saved

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Medical Physics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de Feb. de 2021

Comentada:

el 25 de Feb. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by