I need to correct the script for coloring map
%## Edited so that code runs here
clc;
close all;
clear;
% Read the geological map
% [file, path] = uigetfile(‘*.jpg’, ‘Select the Geological Map File’);
path = ‘./’;
file = ‘Geological map of Mobrun Sulfied.jpg’;
map_image = imread(fullfile(path, file));
% Display the original map
figure;
imshow(map_image);
title(‘Original Map’);
% Convert to RGB if the image is grayscale
if size(map_image, 3) == 1
map_image = cat(3, map_image, map_image, map_image);
end
% Define masks for regions based on RGB values
% Inspect the RGB values of each region using ‘impixelinfo’ or similar
% Example: Rhyolite, Andesite, and Meta-sediments regions
% Replace these thresholds with specific RGB ranges based on your map
ryolite_mask = (map_image(:,:,1) > 200 & map_image(:,:,2) < 100 & map_image(:,:,3) < 100); % Example: Red shades
andesite_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) > 150 & map_image(:,:,3) < 100); % Example: Green shades
meta_sediments_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) < 100 & map_image(:,:,3) > 150); % Example: Blue shades
% Create a copy of the map for coloring
colored_map = map_image;
% Apply colors to the masks
% Rhyolite – Red
colored_map(:,:,1) = colored_map(:,:,1) + uint8(ryolite_mask) * 255; % Red channel
colored_map(:,:,2) = colored_map(:,:,2) – uint8(ryolite_mask) * 255; % Green channel
colored_map(:,:,3) = colored_map(:,:,3) – uint8(ryolite_mask) * 255; % Blue channel
% Andesite – Green
colored_map(:,:,1) = colored_map(:,:,1) – uint8(andesite_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) + uint8(andesite_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) – uint8(andesite_mask) * 255;
% Meta-sediments – Blue
colored_map(:,:,1) = colored_map(:,:,1) – uint8(meta_sediments_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) – uint8(meta_sediments_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) + uint8(meta_sediments_mask) * 255;
% Display the colored map
figure;
imshow(colored_map);
title(‘Colored Geological Map’);
% Save the colored map
imwrite(colored_map, ‘Colored_Geological_Map_Automatic.jpg’);%## Edited so that code runs here
clc;
close all;
clear;
% Read the geological map
% [file, path] = uigetfile(‘*.jpg’, ‘Select the Geological Map File’);
path = ‘./’;
file = ‘Geological map of Mobrun Sulfied.jpg’;
map_image = imread(fullfile(path, file));
% Display the original map
figure;
imshow(map_image);
title(‘Original Map’);
% Convert to RGB if the image is grayscale
if size(map_image, 3) == 1
map_image = cat(3, map_image, map_image, map_image);
end
% Define masks for regions based on RGB values
% Inspect the RGB values of each region using ‘impixelinfo’ or similar
% Example: Rhyolite, Andesite, and Meta-sediments regions
% Replace these thresholds with specific RGB ranges based on your map
ryolite_mask = (map_image(:,:,1) > 200 & map_image(:,:,2) < 100 & map_image(:,:,3) < 100); % Example: Red shades
andesite_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) > 150 & map_image(:,:,3) < 100); % Example: Green shades
meta_sediments_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) < 100 & map_image(:,:,3) > 150); % Example: Blue shades
% Create a copy of the map for coloring
colored_map = map_image;
% Apply colors to the masks
% Rhyolite – Red
colored_map(:,:,1) = colored_map(:,:,1) + uint8(ryolite_mask) * 255; % Red channel
colored_map(:,:,2) = colored_map(:,:,2) – uint8(ryolite_mask) * 255; % Green channel
colored_map(:,:,3) = colored_map(:,:,3) – uint8(ryolite_mask) * 255; % Blue channel
% Andesite – Green
colored_map(:,:,1) = colored_map(:,:,1) – uint8(andesite_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) + uint8(andesite_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) – uint8(andesite_mask) * 255;
% Meta-sediments – Blue
colored_map(:,:,1) = colored_map(:,:,1) – uint8(meta_sediments_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) – uint8(meta_sediments_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) + uint8(meta_sediments_mask) * 255;
% Display the colored map
figure;
imshow(colored_map);
title(‘Colored Geological Map’);
% Save the colored map
imwrite(colored_map, ‘Colored_Geological_Map_Automatic.jpg’); %## Edited so that code runs here
clc;
close all;
clear;
% Read the geological map
% [file, path] = uigetfile(‘*.jpg’, ‘Select the Geological Map File’);
path = ‘./’;
file = ‘Geological map of Mobrun Sulfied.jpg’;
map_image = imread(fullfile(path, file));
% Display the original map
figure;
imshow(map_image);
title(‘Original Map’);
% Convert to RGB if the image is grayscale
if size(map_image, 3) == 1
map_image = cat(3, map_image, map_image, map_image);
end
% Define masks for regions based on RGB values
% Inspect the RGB values of each region using ‘impixelinfo’ or similar
% Example: Rhyolite, Andesite, and Meta-sediments regions
% Replace these thresholds with specific RGB ranges based on your map
ryolite_mask = (map_image(:,:,1) > 200 & map_image(:,:,2) < 100 & map_image(:,:,3) < 100); % Example: Red shades
andesite_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) > 150 & map_image(:,:,3) < 100); % Example: Green shades
meta_sediments_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) < 100 & map_image(:,:,3) > 150); % Example: Blue shades
% Create a copy of the map for coloring
colored_map = map_image;
% Apply colors to the masks
% Rhyolite – Red
colored_map(:,:,1) = colored_map(:,:,1) + uint8(ryolite_mask) * 255; % Red channel
colored_map(:,:,2) = colored_map(:,:,2) – uint8(ryolite_mask) * 255; % Green channel
colored_map(:,:,3) = colored_map(:,:,3) – uint8(ryolite_mask) * 255; % Blue channel
% Andesite – Green
colored_map(:,:,1) = colored_map(:,:,1) – uint8(andesite_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) + uint8(andesite_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) – uint8(andesite_mask) * 255;
% Meta-sediments – Blue
colored_map(:,:,1) = colored_map(:,:,1) – uint8(meta_sediments_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) – uint8(meta_sediments_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) + uint8(meta_sediments_mask) * 255;
% Display the colored map
figure;
imshow(colored_map);
title(‘Colored Geological Map’);
% Save the colored map
imwrite(colored_map, ‘Colored_Geological_Map_Automatic.jpg’); coloring, colormap MATLAB Answers — New Questions