Hi, I tried to divide my file into 2 parallel file: a main file and a function file. Can somebody help me with this?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
type('Lab2Part1.m')
1 Commento
Dyuman Joshi
il 4 Apr 2024
You should specify what exactly you need help with and provide all relevant information.
And there are no functions in the code above.
Risposte (1)
Gayatri
il 4 Apr 2024
Hi Phat,
To divide your script into two parts : a main file and a function file, create a main script that handles user input and image display, and a separate function that processes the image based on the selected color.
- Main File: colorChangeMain.m. This file will handle user interaction and display the original and modified images.
% Load the image
a = imread('coloredChips.png');
figure(1), imshow(a);
% Display color selection menu
disp('Color selection')
disp('r for red')
disp('b for blue')
disp('y for yellow')
disp('m for magenta')
disp('g for green')
disp('c for cyan')
disp('o for orange')
% Get user input for color selection
x = input('Please select the color you want to change: ', 's');
% Call the function to process the image
copy = processColorChange(a, x);
% Display the modified image
figure(2), imshow(copy);
- Function File: processColorChange.m. This function will take the original image and the user-selected color as input, process the image and return the modified image.
function copy = processColorChange(a, x)
% Copy the original image
copy = a;
% Get the dimensions of the image
dimension = size(a);
row_n = dimension(1);
col_n = dimension(2);
% Process the image based on the selected color
switch x
case 'r'
% Insert the case 'r' code block here
case 'b'
% Insert the case 'b' code block here
case 'y'
% Insert the case 'y' code block here
case 'o'
% Insert the case 'o' code block here
case 'g'
% Insert the case 'g' code block here
case 'm'
% Insert the case 'm' code block here
case 'c'
% Insert the case 'c' code block here
otherwise
disp('Incorrect selection, please choose from the menu');
end
end
For each color case ('r', 'b', 'y', 'o', 'g', 'm', 'c'), you should insert the respective code block from your original script into the function processColorChange within the appropriate case section.
I hope it helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!